Skip to content Skip to sidebar Skip to footer

Npm Formidable Upload, Use With Js Formdata On Client

I wanna send a file to the server with FormData by drag and drop, and save it to disk with Formidable in node. I used this code to send the file: https://github.com/felixge/node-f

Solution 1:

After lot's of changes, finally found a way! This is my reader Code:

reader.readAsArrayBuffer(file);

I changed type of file, from buffer to Blob, and it works:

arrayBufferToBlob: function(buffer, opt_contentType) {
    var uInt8Array;
    uInt8Array = newUint8Array(buffer);
    returnnewBlob([uInt8Array], (opt_contentType ? {
        type: opt_contentType
    } : {}));
}

changes of client code:

//Changes of Client:
fd = new FormData;
data = arrayBufferToBlob(data);
fd.append("upload", data, "FileName");

And log of nodeJS server looks like:

fields: {foo:'bar'}
files: {'fileName'}

I think Chrome (not tried on other browsers) HTML File tag uses Blob for HTML Forms to post... If you had idea, tell here!

Post a Comment for "Npm Formidable Upload, Use With Js Formdata On Client"