Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#184 closed defect (fixed)

[patch] POST multipart is added to BrowserIO.js

Reported by: eugene@… 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:

  1. multipart is a Boolean value (true/false). Only POST can use it. Default is false.
  2. 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)

dojo.io.patch (4.2 KB) - added by eugene@… 14 years ago.

Download all attachments as: .zip

Change History (7)

Changed 14 years ago by eugene@…

Attachment: dojo.io.patch added

comment:1 Changed 14 years ago by eugene@…

It looks like Dojo's Trac is up again. Finally I was able to attach the patch.

comment:2 Changed 14 years ago by eugene@…

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:3 Changed 14 years ago by david

Wow, that's awesome.

comment:4 Changed 14 years ago by alex

Milestone: 0.2release

we have a patch and CLA. This should be merged ASAP.

comment:5 Changed 14 years ago by alex

Resolution: fixed
Status: newclosed

(In [2300]) merging file upload patch from Eugene. Required very little in the way of style updates (yay!). A test page is still needed for this feature. Fixes #184

comment:6 Changed 13 years ago by (none)

Milestone: 0.2release

Milestone 0.2release deleted

Note: See TracTickets for help on using tickets.