Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to modify FileReference.data before upload

New Here ,
Mar 16, 2015 Mar 16, 2015

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

TOPICS
ActionScript
354
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 16, 2015 Mar 16, 2015

trace the data's length just prior to your upload line of code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 17, 2015 Mar 17, 2015

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 17, 2015 Mar 17, 2015
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines