Package Exports
- formdata-polyfill
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (formdata-polyfill) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
FormData
A FormData polyfill
npm install formdata-polyfill
Meant to be used with babel, closer-compiler or equivalent (since it's written in es6 using class, WeakMap, Iterators, for...of
)
This doesn't monkey patch xhr#send like Rob--W did here. However this provides you a way to convert the entire form to a blob and send it with xhr or fetch.
fd = new FormData(form)
blob = fd._blob()
// Do this...
// important to set correct mimetype
xhr.setRequestHeader('Content-Type', blob.type) // multipart/form-data; boundary=xxx
xhr.send(blob)
xhr.send(fd) // This don't work... Needs to be a native FormData
Another possible solution is to convert the form to a native FormData but then you would lose all the other methods not supported by the original FormData.
fd = new FormData(form)
fd._asNative() // returns a native formData with all the fields
The current status of the native FormData is this
This lib provides you all the function others don't include
append
with filenamedelete()
,get()
,getAll()
,has()
,set()
entries()
,keys()
,values()
, and support offor...of
- Available in web workers (yes, just include it...)
The reason why Rob--W's version didn't work for me was that it only works in web workers due to FileReaderSync beeing used. I did it with constructing new chunks with the blob constructor instead.
new Blob([string, blob, file, etc])