I’m in the process of setting up a new Kotlin android app that upload images to cloudflare via PHP, however the response i’m getting is “ERROR 5400: Bad request: incomplete multipart stream”.
Here is my current PHP code:
$fields = new CURLFile(‘/home/stuboo/public_html/member_pics/’.$fileName ,‘image/jpeg’, $fileName);
$data = array(‘test_file’ => $fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ‘https://api.cloudflare.com/client/v4/accounts/########/images/v1’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
‘Content-type: multipart/form-data; boundary=—011000010111000001101001’,
‘Authorization: Bearer ###############’,
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo ‘Error:’ . curl_error($ch);
}
curl_close($ch);
file_put_contents(“result.txt”,$result);