eligrey / Blob.js

An HTML5 Blob implementation
Other
1.15k stars 605 forks source link

XHR2 FormData with BlobBuilder for CSS upload of a file in memory #1

Closed sjonnet19 closed 12 years ago

sjonnet19 commented 12 years ago

XHR2 FormData with BlobBuilder for CSS upload of a file in memory

I have this working in Firefox and Chrome but am unable to get this to work in Safari even using you pollyfill.

Can you provide any help / advice.

eligrey commented 12 years ago

BlobBuilder.js fake blobs are only intended to be used with URL.createObjectURL(), and the XHR2 API expects a real blob or string. Do this:

if (blob.fake) {
    request.send(blob.data);
} else {
    request.send(blob);
}
sjonnet19 commented 12 years ago

Thanks

sjonnet19 commented 12 years ago

Sorry to bug you but that didn't work :(

This is with Safari 5.1.2

I am attempt to take a Blob I created from a string using the BlobBuilder and send it as a file in FormData

fd.append('fileToUpload', blob.fake ? blob.data: blob)

eligrey commented 12 years ago

That's odd. I can't reproduce your issue in Safari 5.1.1 FormData. Maybe your server isn't handling it correctly if fileToUpload is a String instead of a File/Blob with a filename, etc.

sjonnet19 commented 12 years ago

How should it handle it... I added logic to detect if it was a string and save it but the string when returned has some differences in it

pauljoey commented 12 years ago

Same issue.

My original solution to upload a canvas image was toDataURL -> Uint8Array -> BlobBuilder -> Blob -> FormData, which works perfectly except on Safari (tested on 5.1 and whatever version is on the iPhone 4GS). Unfortunately the BlobBuilder shim is incompatible with FormData.