REST API: No any response of file upload

Hello

I am trying to upload a file using cURL through php. Here is the code I am using.

$tmpPathName = ‘D:\xampp\tmp\php15AF.tmp’;
$getType = ‘image/png’;

$cfile = new \CURLFile($tmpPathName, $getType, ‘image’);
$postfields = array(“filedata” =>$cfile);

        $curl = curl_init();

        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_URL, 'https://api.backendless.com/xxxx/yyyy/files/Restaurant/image.png/?overwrite=true');
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
        'Content-Type: multipart/form-data')
        );
        $result = curl_exec($curl);
        curl_close($curl);

        echo '<pre>';
        print_r($result);

But I keep getting "No any response (it’s showing blank).
What is it that I am doing wrong here :frowning_face: ?
Thanks

Hi, Richa!

On this line you’re creating a new CURLFile object with mime type ‘image/png’ from some temp file "php15AF.tmp. Is it really an image, which you’re going to upload?

After checking the file path you can try this:

$ch = curl_init(’https://api.backendless.com/xxxx/yyyy/files/Restaurant/image.png/?overwrite=true');

$cfile = curl_file_create(‘tmpPathName’,‘image/png’,‘image’);

$data = array(‘test_file’ => $cfile);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);

Regards,
Andrew