Hello FreeBDevs:<br><br>So we finally got over the hump here; we fired up &#39;tcpflow&#39; (awesome network diagnostic tool, by the way, easier than tcpdump) to monitor the exchange between the local system and freebase.<br>
<br>-The Broken-<br>Freebase&#39;s &#39;raw&#39; upload url (<a href="http://sandbox.freebase.com/api/service/upload">sandbox.freebase.com/api/service/upload</a>) only accepts &#39;POST&#39; requests but doesn&#39;t know how to deal with multipart/form-data as a content type.&nbsp; PHP/libcurl defaults its POST to Content-Type: multipart/form-data,&nbsp; and embeds the image inside of that multipart envelope.&nbsp; Below is the tcpflow output with the broken code, minus some extraneous stuff (
<a href="http://192.168.0.150">192.168.0.150</a> is the local system, <a href="http://208.068.108.121">208.068.108.121</a> is <a href="http://sandbox.freebase.com">sandbox.freebase.com</a>):<br><br>192.168.000.150.46220-208.068.108.121.00080
: POST /api/service/upload HTTP/1.1<br>Content-Type: image/gif<br>Content-Length: 13365<br>Content-Length: 13555<br>Expect: 100-continue<br><br>192.168.000.150.46220-208.068.108.121.00080: Content-Type: multipart/form-data; boundary=----------------------------b8245f93a0cb
<br>------------------------------b8245f93a0cb<br>Content-Disposition: form-data; name=&quot;filename&quot;; filename=&quot;CORAL.gif&quot;<br>Content-Type: image/gif<br><br><br>192.168.000.150.46220-208.068.108.121.00080
: GIF89a+.........).X.T.r....-.w.\.r....1{..d&gt;3o;..5wV.l~3..,g.....;&lt;Image Data Here&gt;<br>192.168.000.150.46220-208.068.108.121.00080: <br>------------------------------b8245f93a0cb--<br><br>208.068.108.121.00080-192.168.000.150.46220
: HTTP/1.0 400 Bad Request<br><br><br>***This lead to the cryptic &quot;cannot identify image file&quot; response from the freebase server.***<br><br><br>-The Fix-<br>Straightforward, but there are no examples of this I could find in Google to use CURLOPT_READDATA instead of CURLOPT_POSTFIELDS:
<br><br>Replace one line:<br>&nbsp;&nbsp; curl_setopt($request, CURLOPT_POSTFIELDS,$content);<br><br>With these two lines, dropping the @ from the front of the file name:<br>&nbsp;&nbsp;&nbsp; $fp = fopen ($content, &quot;r&quot;); <br>&nbsp;&nbsp;&nbsp; curl_setopt($request, CURLOPT_READDATA, $fp); 
<br><br><br>-The New-<br>The working interaction is as follows, note there is no mention of multiparts:<br><br>192.168.000.150.59161-208.068.108.121.00080: POST /api/service/upload HTTP/1.1<br>Content-Type: image/gif<br>Content-Length: 13365
<br>Expect: 100-continue<br><br><br>192.168.000.150.59161-208.068.108.121.00080: GIF89a+............,.&lt;Image Data Here&gt;<br>\.r....1{..d&gt;3o;..5wV.l~3..,g.....;<br>208.068.108.121.00080-192.168.000.150.59161: HTTP/1.0 200 OK
<br><br><br>Hope this leads to less pulled out hair for someone.<br><br>Regards,<br>Indy<br><br><br><div class="gmail_quote">On Dec 30, 2007 2:05 AM, Coral Link &lt;<a href="mailto:corallink@gmail.com">corallink@gmail.com
</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi; I&#39;m using PHP/LibCURL to upload images relevant to my topics.&nbsp; I&#39;m guessing its more of a PHP issue than Freebase, but hopefully someone will indulge a helping hand.
<br><br>I&#39;m running into this problem when uploading an image:
<br><br>{
  &quot;status&quot;: &quot;400 Application Error&quot;, 
  &quot;code&quot;: &quot;/api/status/error&quot;, 
  &quot;messages&quot;: [
    {
      &quot;info&quot;: {
        &quot;exception&quot;: &quot;cannot identify image file&quot;
      }, 
      &quot;message&quot;: &quot;Invalid image file.&quot;, 
      &quot;code&quot;: &quot;/api/status/error/upload/invalid_image_data&quot;
    }
  ]
}<br><br>When I run the following:<br>$content=&quot;@/hole/www/corallink.com/freebase/files/uwlImage/9202a8c04000641f80000000060b61a7/CORAL.gif&quot;;<br>$type=&quot;image/gif&quot;;<br><br>$request = curl_init($url);<br>

curl_setopt($request, CURLOPT_COOKIEFILE, $cookiejarfile);&nbsp; //get some cookies<br>curl_setopt($request, CURLOPT_POST, 1);<br>curl_setopt($request, CURLOPT_HTTPHEADER, array(&quot;X-Metaweb-Request: TRUE&quot;, &quot;Content-Type: &quot;.$type));
<br>curl_setopt($request, CURLOPT_POSTFIELDS,$content);<br><br>// Return the result instead of printing it out.<br>curl_setopt($request, CURLOPT_RETURNTRANSFER, TRUE);<br>curl_setopt($request, CURLOPT_COOKIE, $credentials);
<br>&nbsp;&nbsp;&nbsp; <br>// Now fetch the URL<br>$responsetext = curl_exec($request);<br>curl_close($request);<br><br><br>This same code works great for uploading documents for the description in /common/topic.&nbsp; I&#39;ve tried variations where I&#39;ve made $content=array(&quot;file&quot;=&gt;&quot;@
filename.gif&quot;), which uploaded data, but Freebase tagged it as media_type &#39;octet/stream&#39;.&nbsp; Any suggestions will be appreciated.<br><br>Thank you and kind regards,<br>Indy<br>
</blockquote></div><br>