Start a new topic

RE: 504 - Session Timeout using PHP/cURL

Hi


I wrote you this morning concerning fileupload with PHP/cURL. Its not yet published, thats ok. I have found a solution after some more research. 

For everyone else who wants to upload files (file storage) by PHP/cURL:


// Upload file to Kinvey File Storage
$ch = curl_init ($ch);
curl_setopt( $ch, CURLOPT_PUT, true );
curl_setopt( $ch, CURLOPT_INFILESIZE, <size_of_your_file>);
curl_setopt( $ch, CURLOPT_INFILE, ($in=fopen(<path_with_filename>, 'rb')) ); // b(inary) not mandatory but recommended
// curl_setopt( $ch, CURLOPT_HTTPHEADER, array("Content-Length: " . filesize($myfile)) ); // seems not necessary, covered by CURLOPT_INFILESIZE
curl_setopt( $ch, CURLOPT_HTTPHEADER, []); // Make sure header is empty then if filled by a previous cURL process, otherwise error message
curl_setopt( $ch, CURLOPT_URL, <uploadpath_from_previous_step> );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

$result = curl_exec($ch);
print_r ($result); // -> no output (would be nice to have some as confirmation)
curl_close ($ch);

This is the only way I could make it work. If a file is uploaded successfully you can click the download link in your Kinvey console (File area) in order to download/watch it.


Regards



1 Comment