Copy link to clipboard
Copied
Hi, I'm trying to build a simple image uploader that will allow a user to select a local file, I then need to modify the image and then upload to S3. I'm using FileReference.load() to successfully load the image, turn it in to a Bitmap and back to a ByteArray, but when I try and set the data property of FileReference the original (unedited) file is uploaded. It seems that calling FileReference.upload() ignores the data in the FileReference.data and loads it fresh from the hard drive and posts it off to the server. Is that correct?
In this really simple example I'm not even setting the bytearray to anything new, just clearing it - I would expect it to upload a 0 bytes file or something, but instead it uploads the original file. Is this a bug, am I doing something wrong, or is this correct behaviour?
--
// load the file in to memory
_fileReference.load();
// ... on file reference loaded
trace(_fileReference.data.length); // 230189
_fileReference.data.clear();
trace(_fileReference.data.length); // 0
// With or without this next line it happily uploads the original file (with it commented out I would expect a 0 bytes file, or an error or something)
//_fileReference.data.writeBytes(myNewByteArray);
_fileReference.upload(myURLRequest);
--
Any thoughts greatly appreciated!
Simon
Copy link to clipboard
Copied
trace the data's length just prior to your upload line of code.
Copy link to clipboard
Copied
Thanks for the reply, the data property reads the correct values before and after upload. In the example I posted above it reads 230189, then I clear the bytearray and directly before the upload (and in fact after the upload) it reads 0.
Copy link to clipboard
Copied
i don't think that's going to work.
you can manipulate the filereference's bytearray, but that doesn't change the filereference.
to do what you want i think you should check the jpgencoder or pngencoder.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now