Friday, 8 November 2019

Object of class CURLFile could not be converted to string

How to achieve an image upload via cURL?
I am using zamzar sandbox api for convert pdf file to .txt file. If i use "https://s3.amazonaws.com/zamzar-samples/sample.pdf" path of pdf for $sourceFile variable then its working fine. But if i use system path "test.pdf" then it's not working.

I was trying to through curl_file_create, but it gives the following error:

Recoverable fatal error: Object of class CURLFile could not be converted to string in line.

I am using PHP Version 7.3.0

<?php

    $endpoint = "https://api.zamzar.com/v1/jobs";
    $apiKey = "GiVUYsF4A8ssq93FR48H";
    $sourceFile = "test.pdf";//"https://s3.amazonaws.com/zamzar-samples/sample.pdf";
    $targetFormat = "txt";



    $postData = array(
      "source_file" => $sourceFile,
      "target_format" => $targetFormat
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $endpoint);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_USERPWD, $apiKey . ":");
    $body = curl_exec($ch);
    curl_close($ch);
    $response = json_decode($body, true);
    echo "Response:\n---------\n";
    echo"<pre>";
    print_r($response);

?>


from Object of class CURLFile could not be converted to string

No comments:

Post a Comment