1

I'm trying to grab an image from a remote location, resize it and save it to Amazon S3.

Problem is, I can save the image to S3 allright, but when I try to display it, the browser says image can't be displayed because it contains errors. I'm sure this is due to me doing the following:

a) Grab image from remote location:

  <cfhttp timeout="45" 
      throwonerror="no" 
      url="#variables.testFilePath#" 
      method="get" 
      useragent="Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12" 
      getasbinary="yes" 
      result="objGet">

b) Create image to validate and resize

<cfset objImage = ImageNew(objGet.FileContent);

c) After resizing, I'm converting the resized image (!) back to binary data, because the following function call to S3.cfc needs a valid file path to read the image again as binaryData. I'm doing this:

 <cfset variables.filekey = toBase64( objImage )>

instead of this:

 <cffile action="readBinary" file="#arguments.uploadDir##arguments.fileKey#" variable="binaryFileData">

because I can't get a valid arguments.uploadDir to work, so instead of re-reading the image here, I thought I just convert back to binary data and save this to S3. Which converts my image back to a base64 string, which I then save at S3.

Question:
Can someone tell me what I'm doing wrong? I guess it's the base64 getasbinary and toBase64. But I'm not sure.

Thanks for help!

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
frequent
  • 27,643
  • 59
  • 181
  • 333

1 Answers1

1

You don't need to convert it back to binary. Just use the cfimage tag to write it to disk, and then use the path to send the image off to Amazon. Then delete the image when you're done with it.

Dan Short
  • 9,598
  • 2
  • 28
  • 53
  • @frequent - If you ultimately need to save the image to disk anyway, why not just do that in your `cfhttp` call (as suggested in one of your another threads)? – Leigh Aug 11 '12 at 05:08
  • @Leigh: I had hoped to get by without saving to "my" disk and deleting files after storing on S3. Looks like it doesn't work though :-( – frequent Aug 11 '12 at 09:56
  • @DanShort: I guess I will go with your approach right now, althgouh I was hoping this would be possible without intermim-saving to disk. I only converted back to binary, because the s3.cfc will make an additional `cffile action="readBinary"` which I wanted to avoid and which also requires a valid path, which in turn requires to save to disk, because I couldn't get it to work with a temp path. So my idea was `readbinary>newImage>resize>backtobinary>s3` vs now doing `readbinary>newImage>resize>save-to-disk>re-read-from-disk>s3>delete-from-disk`. – frequent Aug 11 '12 at 10:02
  • Did you try just sending the image object itself? – Dan Short Aug 11 '12 at 16:00
  • ok. I have it working, but need to interim-save-to-disk. Doesn't work without and since this is a potentially repetitive interaction, I also worry about running out of memory. Thanks for the info. – frequent Sep 04 '12 at 08:11