Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8389941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:51:30+00:00 2026-06-09T18:51:30+00:00

I’m using Coldfusion8 and need to fetch images from a remote server, which I’m

  • 0

I’m using Coldfusion8 and need to fetch images from a remote server, which I’m doing like this:

 <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="variables.objGet">
 <cfset variables.objImage = ImageNew(variables.objGet.FileContent)>

I now need to save the image to Amazon S3, but the function I want to use:

 <cfset result = s3.putObject(url.b,file.serverFile,file.contentType,'300',form.cacheControl,'30',form.acl,form.storageClass,form.keyName,GetTempDirectory())>

Requires the directory where my generated image can be found in.

Question:
Is there a way to get the directory of an image file pulled with cfhttp and converted to an image using imageNew? Or do I need to save the file to disk first? I also need to resize before storing, so I might not be able to get by without saving to disk first.

Thanks for pointers!

EDIT:
I got it working like this:

<!--- getAsBinary --->
<cfhttp timeout="45" 
    throwonerror="no" 
    url="#variables.testFilePath#" 
    method="get" 
    useragent="..."         
    getasbinary="yes" 
    result="objGet">

<!--- validate --->
<cfif len(variables.testFilePath) EQ 0>
    <cfset variables.errorCount = variables.errorCount+1>
    <cfset variables.failedLoads = "FILE NOT FOUND" >
<cfelse>
    <cfif len(objGet.Filecontent) EQ 0>
        <cfset variables.errorCount = variables.errorCount+1>
        <cfset variables.failedLoads = "COULD NOT LOAD IMAGE">
    <cfelseif NOT listfindnocase(variables.allow, variables.fileExt) >
        <cfset variables.errorCount = variables.errorCount+1>
        <cfset variables.failedLoads = "WRONG FILE TYPE">
    <cfelse>
        <cftry>
            <cfscript>
                objImage = ImageNew(objGet.FileContent);
                ImageSetAntialiasing(objImage,"on");
                <!--- resize/crop --->
                variables.keyName = Session.loginid & "_S_";
            </cfscript>
            <!--- convert modified image back to binary --->
            <cfset variables.filekey = toBase64( objImage )>
            <!--- pass to s3.cfc --->
            <cfset result = s3.putObject(variables.bucketName, variables.filekey, variables.contentType, variables.httptimeout, variables.cacheControl, variables.cacheDays, variables.acl, variables.storageClass, variables.keyName, variables.imageSrc, "true" )>
            <cfcatch>
                <cfset variables.errorCount = variables.errorCount+1>
                <cfset variables.failedLoads = "NO IMAGE">
            </cfcatch>
        </cftry>
    </cfif>

I need to re-convert the cropped image to binary, because the s3.putobject will otherwise do another cffile action="readBinary" and breaks on trying to construct the image file path (the image is still in temp) right here:

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

While I can get the temporary file path using this trick and set uploadDir it doesn’t help, because CF docs say the path must be either an absolute path starting with drive letter or slash, otherwise the www-root temp directory will be taken.

In my case the temp www-root directory was on C:/ while the temp file CFFile-Servlet was on E:/ and a relative path did not work either (file not found). So as I found no way to re-read the image from the s3.cfc, I’m now converting back to binary before calling S3.cfc. I pass another parameter (1/0) telling s3.cfc, that I’m already sending the binary image and there is no need to re-read it.

Like so:

<!--- if encoded is true, filekey already is the encoded image --->
<cfif arguments.encoded EQ "true">
    <!--- already sending binary image --->
    <cfset binaryFileData = arguments.fileKey>
<cfelse>
    <!--- Default --->
    <cffile action="readBinary" file="#arguments.uploadDir##arguments.fileKey#" variable="binaryFileData">
</cfif>

I’m not sure if this is the smartest way performance wise, but it seems to work pretty smooth. Comments are welcome!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:51:31+00:00Added an answer on June 9, 2026 at 6:51 pm

    I guess you could use path and file attributes instead of result. Generate some temporary path using GetTempDirectory() + CreateUUID(), fetch and then drop it. Plus it may be a bit more memory-efficient thatn fetching content to the variable, then writing to the intermediate file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have thousands of HTML files to process using Groovy/Java and I need to
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.