Friday, January 6th, 2006

Dojo: Uploading files, and contents with Ajax

Category: Dojo, Toolkit

Dojo makes it very easy to submit forms with Ajax, using the dojo.io.bind() wrapper.

All you have to do is add formNode: document.getElementById('foo') to the argument object and you are set.

But what about uploading files?

Alex has written up file uploading with Dojo, where he shows us that we can simply add dojo.require("dojo.io.IframeIO"); to use the iframe IO transport, which is able to upload files.

He then posts about file upload… without the file!, which shows how you can send any stream of content up as though it is a file upload, using the XMLHttpTransport and:

dojo.io.bind({
  url: "upload.cgi",
  // we expect to get JSON back from this CGI
  mimetype: "text/json",
  // handle the returned JSON
  load: function(type, data, evt){  },
  // normal properties
  content: {
    foo: "bar",
    baz: "thud"
  },
  // our file content
  file: {
    name: "upload.txt",
    contentType: "plain/text",
    content: "look ma! no form node!"
  }
});

Posted by Dion Almaer at 9:39 am
10 Comments

+++--
3.7 rating from 106 votes

10 Comments »

Comments feed TrackBack URI

[…] NOTE: we talked about uploading files and contents with Dojo […]

Pingback by Ajaxian » PORK.iframe: Form submission with iframes — January 18, 2006

[…] Dojo toolkit’s new file uploading feature […]

Pingback by Ajaxian » Audible Ajax Episode 14: State of Ajax in Denmark — February 6, 2006

s

Comment by s — May 19, 2006

This is a kind of cheating. No one can upload files using AJAX. But ys little bit of cheating can make the process look like ajax stuff. good job.

Comment by Kumar — June 6, 2006

There is not enough information about how to handle, upload and process multipart-formdata oriented file uploads. What I have found as example is :

file: {
name: “upload.txt”,
contentType: “plain/text”,
content: “look ma! no form node!”
},
But who will process the upload, what about multiple files???

ramanbasu@gmail.com

Comment by Raman Basu — July 4, 2006

Ramaan,
You can check out my free script – I borrowed a lot of code for the server side scripts (check the copyright information in the files) but I totally rewrote the JavaScript because I was not happy with the way a lot of scripts out there handled the process or the freakin’ size of the things, either. Totally script size with proper compression is under 5KB! You can check it out by clicking on the link below.

Comment by Free Small AJAX File Upload Script — September 1, 2006

Still trying to find a way to make it work for a client. :o(

Comment by Lautreamont — October 4, 2006

file storage

http://www.Dead-Yahoo.com is a very dynamic, complex server that allows you to upload and download as many files as you can possibly imagine! With up to 2GB upload capacity that no other server allows, Dead-Yahoo is unquestionably the best on the net. Not onl…

Trackback by Ankit Talwar — October 13, 2006

Thtat wat i was looking for.

Comment by Java — October 19, 2007

Hi,

You can now use ( dojo version > 1.3 ) dojo.io.iframe.send
Take a look at my website to see a demo : http://developers.sirika.com/mfu/

Cheers

Comment by Zebulons — May 9, 2010

Leave a comment

You must be logged in to post a comment.