Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过第三方软件将文件上传至S3 bucket_Php_Amazon S3_Curl - Fatal编程技术网

Php 通过第三方软件将文件上传至S3 bucket

Php 通过第三方软件将文件上传至S3 bucket,php,amazon-s3,curl,Php,Amazon S3,Curl,所以我正在开发一个WordPress网站,它有Web2Print designer,我正试图在这个设计器上实现删除背景功能。基本上,我从Web2Print抓取一个图像,将其发布到API,然后接收带有移除背景的图像。Web2Print的开发人员说,我需要将图像上传到他们的S3 bucket,然后将URL(S3 bucket文件)发送回Web2Print,并将其放在画布上,并在应用程序中使用 在Web2Print中,我可以做到这一点 let _comm = Box.Application.getSe

所以我正在开发一个WordPress网站,它有Web2Print designer,我正试图在这个设计器上实现删除背景功能。基本上,我从Web2Print抓取一个图像,将其发布到API,然后接收带有移除背景的图像。Web2Print的开发人员说,我需要将图像上传到他们的S3 bucket,然后将URL(S3 bucket文件)发送回Web2Print,并将其放在画布上,并在应用程序中使用

在Web2Print中,我可以做到这一点

let _comm = Box.Application.getService('comm');
_comm.post('upload/', { contentType: 'image/png', ext: 'png', rawPath: 'assets/' }) 
.then(_data => {...});
如果我使用控制台日志
\u data
我会得到以下信息

fields: 
  Key: "raw/<SOME HASH>.png"
  Policy: "<SOME OTHER HASH>"
  X-Amz-Algorithm: "AWS4-HMAC-SHA256"
  X-Amz-Credential: "<SOME HASH>/20210514/eu-west-1/s3/aws4_request"
  X-Amz-Date: "20210514T094324Z"
  X-Amz-Security-Token: "<SOME HASH>"
  X-Amz-Signature: "<SOME HASH>"
  bucket: "<BUCKET NAME>"
url: "<URL>"
注意:
$imageRemoveBackgroundUrl
是一个avlid ULR字符串

这个密码什么也没给我。如果我运行
curl\u getinfo($ch,CURLINFO\u HTTP\u code)
我得到空字符串,如果我运行
curl\u error($ch)
我也得到空字符串,如果我运行
curl\u errno($ch)
我也得到空字符串

如果我替换这行代码
'file'=>新文件(realpath($imageRemoveBackgroundUrl)、“image/png”、“no bg.png”)
用这个
'file'=>$imageRemoveBackgroundUrl
我在
responseText
中得到
InvalidArgument

我也尝试过这样做,但没有任何效果。
'x-amz-content-sha256'=>哈希('sha256',file_get_contents($imageRemoveBackgroundUrl))
,仍然获取无效参数

Web2Print公司的技术支持人员说,我需要将整个
\u数据
对象传递到
curl
,而不进行任何更改,所以我这样做了,并且我遇到了这个错误
预处理失败
,但我认为这不起作用,因为我需要上传
\u数据
对象不知道的文件

那么有可能做到我想做的事情吗

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
  'Content-Type' =>  "image/png",
   // 'acl' => '',
  'Key' => $key,
  'Policy' =>  $policy,
  'X-Amz-Algorithm' => 'AWS4-HMAC-SHA256',
  'X-Amz-Credential' => $credential,
  'X-Amz-Sate' => $bucketDate,
  'X-Amz-Aignature' => $signature,
  'X-Amz-Security-Token' => $security_token, 
  'file' => new CurlFile(realpath($imageRemoveBackgroundUrl), "image/png", 'no-bg.png')
]);

$response = curl_exec($ch);

$staus_code;
$error_log = curl_errno($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 204) {
  echo 'Success!';
  $status_code = 204;
} else {
  $error = substr($response, strpos($response, '<Code>') + 6);
  echo substr($error, 0, strpos($error, '</Code>'));
  $status_code = substr($error, 0, strpos($error, '</Code>'));
}
curl_close($ch);