[Intermediate] Multiple File Upload


(Nic Hubbard) #1

Want to see a video demo?
Watch a Demo Video of this in action

Using Upload Progress bar:

Watch a Demo Video of this in action

Pretty Multiple Upload Progress Bars using an Asset Builder

Watch a Demo Video of this in action



I have been wanting this feature to be part of the asset builder asset for some time but I am not sure that will ever happen. So, I went out to find my own method of uploading multiple files, mainly image files, to our server. Here are the steps to get a nice, easy, and scalable solution.


  1. First, create an Asset Builder asset. Configure it to build image assets (or any other file assets).



    [attachment=413:Picture 1.png]


  2. Go to the Create Locations screen. We are going to be using dynamic create locations, so setup up a get variable using location as the name. Then, set your create location restriction and allowed asset types. (You could use a static create location if you wanted, but not as flexible)



    [attachment=414:Picture 2.png]


  3. Next, add a custom create form layout for the Asset Builder, and add just the %details-F_file_upload% keyword.


  4. We will need to add some jQuery code which starts our upload once you choose your file. It will also show a "uploading" image and text.

    Note: You will need to use the ID of your asset builder form, not the example. Use the format page_asset_builder_<your asset builder id>


    $(document).ready(function() {
    	$('#image_0_use_editor_button').remove();
    	$('#page_asset_builder_56570 :file').change(function() {
    		$('#page_asset_builder_56570').submit();
    		$(this).hide();
    		$(this).after('

Please wait, your image is uploading...

'); }); });


5. Create a Standard Page asset, this will be our page that will actually be viewed and interacted with.

6. We need edit our Standard Page and add some more jQuery which will create an iframe, with our asset builder each time we click the "Add" button. In doing this, we add our get variable to the asset builder once it loads so that it knows where to create the asset. (You could use a static create location if you wanted, but not as flexible).

    $(document).ready(function() {
    	$('#add').click(function() {
    		$('').appendTo('#frames');
}); });


[b]NOTE[/b]: You will need to insert your asset id's instead of the ones in this examples. Also, note that the URL for the iframe has two ? in the URL, this is correct, as Matrix will replace the ./?a= style link, leaving only the second ? which is correct.

7. Next, add some HTML to our standard page so that we have a button to click, as well as a container to add the iframes to.

    


8. Preview our standard page and click add to add some upload fields.

[attachment=415:Picture 3.png]

9. Select some images, and start uploading!

[b]Want to see a video demo?[/b]
Watch a Demo Video of this in action
[b]Using Upload Progress bar:[/b]
Watch a Demo Video of this in action
[b]Pretty Multiple Upload Progress Bars using an Asset Builder[/b]
Watch a Demo Video of this in action Picture 1.png (29.5 KB) Picture 2.png (42.8 KB) Picture 3.png (10.1 KB)

(Robin Shi) #2

Nice job Nic! jQuery+iFrame seems the best workaround for Matrix before the Ajax interface comes out. :rolleyes:


(Nic Hubbard) #3

[quote]
Nice job Nic! jQuery+iFrame seems the best workaround for Matrix before the Ajax interface comes out. :rolleyes:

[/quote]



Well, Ajax can't submit files anyways, so iFrames will always need to be used. Yes, I will work up a much sexier demo for the MySource Matrix Community, so you can utilize ajax, but still submit to an iFrame. But, in the end, the iframe is always there.


(Robin Shi) #4

[quote]
Well, Ajax can’t submit files anyways, so iFrames will always need to be used. Yes, I will work up a much sexier demo for the MySource Matrix Community, so you can utilize ajax, but still submit to an iFrame. But, in the end, the iframe is always there.

[/quote]

I cannot imagine any sexier than the demo you showed in the last conference. I cannot wait!:lol:’ />:lol:<img src=‘http://forums.matrix.squiz.net/public/style_emoticons/<#EMO_DIR#>/laugh.gif’ class=‘bbc_emoticon’ alt=’:lol:.


(Duncan Robertson) #5

WTF! This is awesome. You Nic, are a guru.


(Duncan Robertson) #6

My favorite part is:

     $('#image_0_use_editor_button').remove();

(Nic Hubbard) #7

[quote]
My favorite part is:


     $('#image_0_use_editor_button').remove();

[/quote]



Ha! Yes, I hate that stupid button. Funny thing is, I can never get it to disappear just using css, I have always had to use JS.


(Duncan Robertson) #8

Ah man, we all like

    visibility:hidden; display:none;


on that button's ass all the time.

(Nic Hubbard) #9

[quote]
Ah man, we all like


    visibility:hidden; display:none;


on that button's ass all the time.
[/quote]

Trust me, I have tried it. For some reason does not work well within our site.

Instead, I choose to just remove it from the DOM. My next move is to just remove it from the php code. :)

(Duncan Robertson) #10

Just watching your video again. Wondering what's up with your speed of upload? Are those files large?


(Nic Hubbard) #11

[quote]
Just watching your video again. Wondering what's up with your speed of upload? Are those files large?

[/quote]



They are each 100k. The speed issue is our server. It is very slow nowadays creating assets. We need to get Squiz to look at it.


(Nic Hubbard) #12

Just a quick update. I have a ajax progress upload bar working with Matrix. Pretty excited about it. I will work on a new demo using this method, BUT, I will save the actual tutorial until the MySource Matrix Community is launched. :slight_smile:


(Nic Hubbard) #13

Here is a quick demo using the upload progress bar:


http://www.puc.edu/__data/assets/video_file/0005/56768/Snapz-Pro-XScreenSnapz001.mov



Get excited for an awesome file upload demo on the MySource Matrix Community. :slight_smile:


(Mark Brydon) #14

For continuing to raise the bar on implementations - well done! B)


(Duncan Robertson) #15

WTF! Nic, officially the uber matrix user…


(Nic Hubbard) #16

Update


I have been working on perfecting this method in the last few days, and I have something that I think is pretty dang cool! If you are interested, check out the video demo below. It shows how each progress bar can be styled how ever you want (or created how ever you want). You can also return the total size and the current loaded size which is constantly changing. The function returns bytes, so I have another function that converts this to K, MB, GB, etc, so it looks very nice. It is all extremely flexable, I have used jQuery, and there were no modifications to PHP or Matrix code. It is all code that anyone could easily add to an asset builder for the same functionality.



Anyone interested yet? :slight_smile:



Pretty Multiple Upload Progress Bars using an Asset Builder

http://www.puc.edu/__data/assets/video_file/0011/56846/Multiple-Upload.mov


(Rachel Macdonald) #17

It is very cool! :slight_smile:


(Robin Shi) #18

[quote]
Update



I have been working on perfecting this method in the last few days, and I have something that I think is pretty dang cool! If you are interested, check out the video demo below. It shows how each progress bar can be styled how ever you want (or created how ever you want). You can also return the total size and the current loaded size which is constantly changing. The function returns bytes, so I have another function that converts this to K, MB, GB, etc, so it looks very nice. It is all extremely flexable, I have used jQuery, and there were no modifications to PHP or Matrix code. It is all code that anyone could easily add to an asset builder for the same functionality.



Anyone interested yet? :slight_smile:



Pretty Multiple Upload Progress Bars using an Asset Builder

http://www.puc.edu/__data/assets/video_file/0011/56846/Multiple-Upload.mov

[/quote]

That gave me a real shock!:D:D:D

I never knew Matrix returns the uploading progress. I really wanna know how you did it!:o:o:o



Robin


(Nic Hubbard) #19

[quote]
I never knew Matrix returns the uploading progress.

[/quote]



:)’ /> Matrix does not. But, I will give you a hint. If you can pipe your uploads through a flash object, even if you are using just that small piece of flash, you can then return data about the uploading file for each instance. Then, you can use jQuery along with any html and css that you want to build and style your upload bars. Of course with a heap of JS thrown into the mix to get things working. <img src=‘http://forums.matrix.squiz.net/public/style_emoticons/<#EMO_DIR#>/smile.gif’ class=‘bbc_emoticon’ alt=’:slight_smile:


(Robin Shi) #20

[quote]
:)’ /> Matrix does not. But, I will give you a hint. If you can pipe your uploads through a flash object, even if you are using just that small piece of flash, you can then return data about the uploading file for each instance. Then, you can use jQuery along with any html and css that you want to build and style your upload bars. Of course with a heap of JS thrown into the mix to get things working. <img src=‘http://forums.matrix.squiz.net/public/style_emoticons/<#EMO_DIR#>/smile.gif’ class=‘bbc_emoticon’ alt=’:slight_smile:

[/quote]



Aha! Thanks for the trick! :lol: At the first glance I did think it’s js instead of flash, now i see:D