gpt4 book ai didi

php - 低级 API 分段文件上传过程不起作用

转载 作者:搜寻专家 更新时间:2023-10-31 21:23:27 25 4
gpt4 key购买 nike

我们正在尝试通过多部分文件上传过程上传文件。通过使用下面给出的代码:

while (!feof($file)) {

$result = $s3->uploadPart(array(
'Bucket' => $bucket,
'Key' => $key,
'UploadId' => $uploadId,
'PartNumber' => $partNumber,
'Body' => fread($file, filesize($filename))
));
$parts[] = array(
'PartNumber' => $partNumber++,
'ETag' => $result['ETag'],
);
}

//4.完成分段上传。

$result = $s3->completeMultipartUpload(array(

'Bucket' => $bucket,
'Key' => $key,
'UploadId' => $uploadId,
'Parts' => $parts,
));
$url = $result['Location'];

fclose($file);

通过使用此代码,文件被转换为 Multipart 但无法上传文件。它通过 print_r 显示这种类型的错误:

Guzzle\Service\Resource\Model Object
(

[structure:protected] =>
[data:protected] => Array
(
[ServerSideEncryption] =>
[ETag] => "fcfc6838dfrtefr87b27b642e7d63021"
[SSECustomerAlgorithm] =>
[SSECustomerKeyMD5] =>
[RequestId] => 4RTYPEFE054567369BD46D
)

)

正在上传/tmp/phplA534j 的第 2 部分。

Guzzle\Service\Resource\Model Object
(

[structure:protected] =>
[data:protected] => Array
(
[ServerSideEncryption] =>
[ETag] => "d41d8uytrf67fdfrf00b204e9800998ecf8427e"
[SSECustomerAlgorithm] =>
[SSECustomerKeyMD5] =>
[RequestId] => YTYPO67167874586EF802536C
)

)

正在上传/tmp/phplA534j 的第 3 部分。

你能帮帮我吗?

最佳答案

两件事。首先,您可以使用 SourceFile 而不是 Body:

$result = $s3->uploadPart(array(
'Bucket' => $bucket,
'Key' => $key,
'UploadId' => $uploadId,
'PartNumber' => $partNumber,
'SourceFile' => 'Path/To/Your/File.ext')
));

其次,这不是完成上传的正确方法:

$result = $s3->completeMultipartUpload(array(

'Bucket' => $bucket,
'Key' => $key,
'UploadId' => $uploadId,
'MultipartUpload' =>array('Parts'=> $parts),
));

关于php - 低级 API 分段文件上传过程不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41391685/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com