如何通过cURL实现图片上传?
我正在使用沙盒api将pdf文件转换为.txt文件。如果我使用"https://s3.amazonaws.com/sample.pdf"作为pdf的路径来设置
我试图通过
以上示例给我输出结果很好。如果我从系统路径中替换
我正在使用沙盒api将pdf文件转换为.txt文件。如果我使用"https://s3.amazonaws.com/sample.pdf"作为pdf的路径来设置
$sourceFile变量
,则一切正常。但是,如果我使用系统路径“test.pdf”,则它不起作用。我试图通过
curl_file_create
来解决问题,但会出现以下错误:
可恢复致命错误:无法将类CURLFile的对象转换为字符串。
我正在使用PHP版本7.3.0
<?php
error_reporting(E_ALL);
$endpoint = "https://api.xxx.com/v1/jobs";
$apiKey = "GiVU******FR48H";
$sourceFile = "https://s3.amazonaws.com/sample.pdf";//new CurlFile("test.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_SAFE_UPLOAD, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
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);
?>
Response: ---------
Array
(
[id] => 8442473
[key] => GiVU******FR48H
[status] => initialising
[sandbox] =>
[created_at] => 2019-11-12T10:35:01Z
[finished_at] =>
[import] => Array
(
[id] => 671784
[url] => https://s3.amazonaws.com/sample.pdf
[status] => initialising
)
[target_files] => Array
(
)
[target_format] => txt
[credit_cost] => 0
)
以上示例给我输出结果很好。如果我从系统路径中替换
amazonaws
,那么它就不会给出任何响应。
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: image/jpeg"));
- IsThisJavascript