Developers

Flat
File Upload with PHP
User: brynnb
Date: 11/8/2014 11:44 pm
Views: 4067
Rating: 0

I've spent many hours and had several people in the chat try to help to no avail.

I'm getting this error trying to use the /api/file to create a file

string(142) "{ "error" : { "data" : "file", "message" : "'file' is not a text field. You need to upload a file.", "code" : 444 } } "

I've tried passing the 'file' as a string containing the URL of the image file, as well as using this method:

http://subinsb.com/upload-image-to-remote-server-with-php-curl-and-handling-file-in-remote-server

Also, the python example does this:

files = { 'file': open('example.png','rb') }
response = requests.post(url + "/file", params=params, files=files)

I tried doing the same in PHP:
$data = fopen($filename, "rb");
$postData = array('session_id' => $sessionid, 'file' => $data, 'folder_id' => $folderid, 'name' => 'testnamefile1');


But that doesn't seem to work. I'm also sort of confused because in the python example it looks like it's passing a stream, whereas in jQuery, Perl, and Curl examples it seems to only be passing the path to the image.

Re: File Upload with PHP
User: brynnb
Date: 11/9/2014 0:44 am
Views: 2174
Rating: 0

I hate myself for working on this for so long.

It turns out you do just send the file path, but you need an “at” sign (@) before the file path makes sure that cURL sends the file as part of a “multipart/form-data” post. 

 

Well it sucks it took me 4+ hours to figure this out but here it is if anyone else needs it.

PreviousNext