This Question is related to and inspired by How to updoad in old browsers (ex Safari 5.1.4)
Given an element having a
files
property containing File
objects which inherit from Blob
, is it possible to create a ArrayBuffer
and convert the ArrayBuffer
to a data URI
from a Blob
or File
object without using FileReader
?
Approaches have tried so far have been
create a mock
WebSocket
with.binaryType
set to"arraybuffer"
, create aMessageEvent
withevent.data
set toFile
object; result isFile
object atonmessage
handlerset prototype of
File
toArrayBuffer
,Uint8Array
; result isUncaught TypeError: Method ArrayBuffer.prototype.byteLength called on incompatible receiver #
,() Uncaught TypeError: Method get TypedArray.prototype.byteLength called on incompatible receiver [object Object]()
set
File
atFormData
object, attempt to post request body to, admittedly not well-conceived; result
Bad Request
at plnkr
Expected result: Convert Blob
and File
objects to TypedArray
then to data URL
, or directly to data URL
See also Display image from blob using javascript and websockets , How can you encode a string to Base64 in JavaScript? ; interestingly ironic as am now asking similar Question https://stackoverflow.com/questions/34302231/is-there-any-way-to-convert-the-file-to-an-arraybuffer-without-filereader-api ; Blob
.slice()
method , FileReader
.readAsDataURL()
method