title: Upload Files from web url using Coldfusion
body: <p>I have been allowing user to upload file via a form online like this:</p>
  
  <pre><code>&lt;form action="upload.htm" enctype="multipart/form-data" name="upload_form" method="post"&gt;
  &lt;input type="file" name="upfile"&gt;
  &lt;input type="submit" name="upload" value="Upload Photos"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Then on the back end the cffile would upload the file:</p>
  
  <pre><code>&lt;cffile action="upload" destination="#currentpath#" accept="image/jpeg, image/gif, image/png" fileField="form.upfile" nameconflict="makeunique"&gt;
  </code></pre>
  
  <p>Now I want to do automation so that the image file does not have to be sitting in the user's computer but rather from a web destination e.g. <a href="http://www.sample.com/images/myimage.jpg" rel="nofollow noreferrer">http://www.sample.com/images/myimage.jpg</a> instead of c:/images/myimage.jpg</p>
  
  <p>I have tried this:</p>
  
  <pre><code>&lt;cfhttp method="get" url="http://www.example.com/images/myimage.jpg"  resolveurl="Yes" throwOnError="Yes"&gt;
  &lt;cfif cfhttp.mimeType eq "image/jpeg"&gt;
      &lt;cfset currentpath = expandpath('/test/')&gt;
      &lt;cffile action="upload" destination="#currentpath#" accept="image/jpeg, image/gif, image/png" fileField="#cfhttp.fileContent#" nameconflict="makeunique"&gt;
  &lt;/cfif&gt;
  </code></pre>
  
  <p>However, it is giving me an error:</p>
  
  <blockquote>
    <p>Invalid content type: ''. The files upload action requires forms to
    use enctype="multipart/form-data"</p>
  </blockquote>
  
  <p>I am not using a form to upload but it seems to require a form field.    </p>
  
  <p>So I tried this:</p>
  
  <pre><code>&lt;cfhttp method="get" url="http://www.example.com/images/myimage.jpg"  resolveurl="Yes" throwOnError="Yes"&gt;
  &lt;cfif cfhttp.mimeType eq "image/jpeg"&gt;
      &lt;cfset currentpath = expandpath('/test/')&gt;
      &lt;cffile action="write" output="#cfhttp.fileContent#"  file="#currentpath#/someimage.jpg"&gt;
  &lt;/cfif&gt;
  </code></pre>
  
  <p>This one writes out a "file" called someimage.jpg but the output is NOT a jpg file, but something unrecognizable.  With the cffile "write", it doesn't allow to check for image type or same file name.</p>
  
  <p>Any help is appreciated.  Thank you in advance.</p>