Multiple file upload with jquery ajax and FormData

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Multiple file upload with jquery ajax and FormData

unseok
Hi Smalltalkers,

I am an absolute newbie to smalltalk (and seaside) in need of your great wisdom on file upload.

What I am trying to do is allow users to drag a file (or files) from their desktop and drop it to a <div> tag to trigger file upload.  I have it working with php but not sure how to translate this to smalltalk way.

On the browser side I am doing the following using javascript (and jquery):
1. preventDefault() on both 'dragover' and 'drop' to prevent browser from opening the file on drag and drop.
2. append each file to FormData :

   for (filename in filelist) {
      formData.append(filename, filelist[filename]);
    }

3. Then fire an ajax call with formData:

        $.ajax({
                url: 'php/fileupload.php',
                data: formData,
                processDate: false,
                contentType: false,
                type: 'POST',
                success: function(data) {
                        alert("File upload completed");
                        removeAll();
                },
                error: function(a, b, c) {
                        alert("Error: " + c);
                }
        });

But, I am lost when it comes to target url (in red) for this ajax request.

On the server side, I have a simple php that handles the request:

<?php
    foreach ($_FILES as $filename => $file) {
      if ($_FILES[$filename]["error"] > 0) {
        echo "Error: " . $_FILES[$filename]["error"];
      } else {
        move_uploaded_file($_FILES[$filename]["tmp_name"], "upload/" . $_FILES[$filename]["name"]);
      }
    }
?>

Your help will be greatly appreciated.



Un-Seok
Reply | Threaded
Open this post in threaded view
|

RE: Multiple file upload with jquery ajax and FormData

Robert Sirois
Is that JavaScript on a static page or is it generated by Seaside? I would suggest writing your jQuery with the Seaside package. That way, you can just call a method on your WAComponent and receive the data that way.

http://demo.seaside.st/javascript/jquery

RS

> Date: Fri, 22 Feb 2013 09:28:31 -0800

> From: [hidden email]
> To: [hidden email]
> Subject: [Seaside] Multiple file upload with jquery ajax and FormData
>
> Hi Smalltalkers,
>
> I am an absolute newbie to smalltalk (and seaside) in need of your great
> wisdom on file upload.
>
> What I am trying to do is allow users to drag a file (or files) from their
> desktop and drop it to a <div> tag to trigger file upload. I have it
> working with php but not sure how to translate this to *smalltalk way*.
>
> On the browser side I am doing the following using javascript (and jquery):
> 1. preventDefault() on both 'dragover' and 'drop' to prevent browser from
> opening the file on drag and drop.
> 2. append each file to FormData :
>
> for (filename in filelist) {
> formData.append(filename, filelist[filename]);
> }
>
> 3. Then fire an ajax call with formData:
>
> $.ajax({
> *url: 'php/fileupload.php'*,
> data: formData,
> processDate: false,
> contentType: false,
> type: 'POST',
> success: function(data) {
> alert("File upload completed");
> removeAll();
> },
> error: function(a, b, c) {
> alert("Error: " + c);
> }
> });
>
> But, I am lost when it comes to target url (in red) for this ajax request.
>
> On the server side, I have a simple php that handles the request:
>
> <?php
> foreach ($_FILES as $filename => $file) {
> if ($_FILES[$filename]["error"] > 0) {
> echo "Error: " . $_FILES[$filename]["error"];
> } else {
> move_uploaded_file($_FILES[$filename]["tmp_name"], "upload/" .
> $_FILES[$filename]["name"]);
> }
> }
> ?>
>
> Your help will be greatly appreciated.
>
>
>
> Un-Seok
>
>
>
> --
> View this message in context: http://forum.world.st/Multiple-file-upload-with-jquery-ajax-and-FormData-tp4671533.html
> Sent from the Seaside General mailing list archive at Nabble.com.
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: Multiple file upload with jquery ajax and FormData

unseok
Hi Robert,

I am using an external javascript file with "updateRoot:" method.

I will definitely try to write my jQuery within the seaside package.

cheers
Reply | Threaded
Open this post in threaded view
|

RE: Multiple file upload with jquery ajax and FormData

Gastón Dall' Oglio
Hello.

If you want a complete solution for file upload packaged as an jquery plugin, have a look at http://blueimp.github.com/jQuery-File-Upload/

Regards.

2013/2/25 unseok <[hidden email]>
Hi Robert,

I am using an external javascript file with "updateRoot:" method.

I will definitely try to write my jQuery within the seaside package.

cheers




--
View this message in context: http://forum.world.st/Multiple-file-upload-with-jquery-ajax-and-FormData-tp4671533p4671989.html
Sent from the Seaside General mailing list archive at Nabble.com.
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside