#184 closed defect (fixed)
[patch] POST multipart is added to BrowserIO.js
Reported by: | Owned by: | anonymous | |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | Core | Version: | 0.1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
API Additions
Two more arguments are added to the request:
- multipart is a Boolean value (true/false). Only POST can use it. Default is false.
- file is an object describing file or an array of objects describing files:
- name is a simulated file field name (required). It is used by servers to handle your input.
- content is a byte string, which represent the content of your file (required).
- fileName is a name of your file (optional). Some servers may use it. If it is not present, name value is used.
- contentType is a MIME type of your file (optional). Some servers may use it. If it is not present, application/octet-stream is used.
If file is present, multipart is automatically forced to true and method is forced to POST. Request's members postContent and contentType trump everything else like they did before.
multipart can be used for sending field values even if you don't need to transfer files. It has two benefits:
- No value encoding is required during preparation step. It maybe useful in some cases.
- Many servers have size restrictions for non-multipart POST to improve performance and prevent possible exploits. In this case switching to multipart can make transfers possible.
Examples
Sending some values using multipart POST
dojo.io.bind({ url: "http://site.my/processor/", content: { item: "key", value: 12345 }, method: "POST", multipart: true, load: function(type, response, evt) { Save(response); }, mimetype: "text/plain" });
Sending a file
dojo.io.bind({ url: "http://site.my/processor/", content: { item: "key", value: 12345 }, file: { upload: "upload", content: "Hello! World! " }, load: function(type, response, evt) { Save(response); }, mimetype: "text/plain" });
In this example method and multipart are not specified directly, because the mere presence of file implies:
multipart: true, method: "POST"
Upload two files
dojo.io.bind({ url: "http://site.my/uploader/", file: [ { upload: "upload1", fileName: "hello.txt", content: "Hello! World! " }, { upload: "upload2", fileName: "test.js", content: "test = Calculate();", contentType: "application/javascript" } ], load: function(type, response, evt) { Save(response); }, mimetype: "text/plain" });
Notes
I tested this implementation with FF1.5 and IE6.
Attachments (1)
Change History (7)
Changed 15 years ago by
Attachment: | dojo.io.patch added |
---|
comment:1 Changed 15 years ago by
comment:2 Changed 15 years ago by
Just noticed that in examples I used upload instead of name. Obviously name should be used everywhere. upload came from my previous version.
PS: I don't know how to modify my original post.
comment:4 Changed 15 years ago by
Milestone: | → 0.2release |
---|
we have a patch and CLA. This should be merged ASAP.
comment:5 Changed 15 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
It looks like Dojo's Trac is up again. Finally I was able to attach the patch.