带有 UploadId 和 PartNumber 的 AWS getSignedUrl

AWS getSignedUrl with UploadId and PartNumber

我正在尝试将以下 JS 转换为 PHP:

client.getSignedUrl('uploadPart', {
    Bucket: config.bucket,
    Key: key,
    UploadId: uploadId,
    PartNumber: partNumber,
    Body: '',
    Expires: ms('5 minutes') / 1000
}, (err, url) => {
    if (err) {
        next(err)
        return
    }
    res.json({ url })
})

Here's the origin

我无法在 AWS 文档中找到 PHP 的等效项,而且我也找不到 AWS docs for the JS 中引用“UploadId”和“PartNumber”的位置。

有人知道我可能遗漏了什么吗?


我正在尝试使用 AWS S3 创建分段上传。我不确定这是不是缺失的部分,但我相信是。

如果我使用 AWS 分段上传纯粹 PHP 上传一个大文件,它可以工作。不过,我需要做的是将上传过程移到客户端。为此,我需要一个预签名的 URL 来上传到。

上面的代码片段来自 Uppy 配套控制器。我很确定它会生成一个预签名 URL,其中包含一些数据,例如 UploadId 和 PartNumber。我一直无法找到一种方法来做到这一点 server-side/PHP。

这会生成一个 URL,我可以上传到它,但我认为它没有添加 UploadId 和 PartNumber:

$cmd = $client->getCommand('PutObject', [
    'Bucket'        => 'bucket-name',
    'Key'           => $key,
    'UploadId'      => $uploadId, // I didn't see a ref to this in the docs
    'PartNumber'    => $partNumber, // Or this.
]);

当我尝试使用预签名 URL 上传部分后使用此代码完成上传时:

$result = $client->completeMultipartUpload([
    'Bucket'          => 'bucket-name',
    'Key'             => $key,
    'UploadId'        => $uploadId,
    'MultipartUpload' => [
        'Parts' => $parts,
    ],
]);

我收到以下错误:

"Error executing "CompleteMultipartUpload" on "https://bucket-name.s3.amazonaws.com/NewProject.png?uploadId=nlWLdbNgB9zgarpLBXnj17eOIGAmQM_xyBArymtwdM71fhbFvveggDmL6fz4blz.B95TLhMatDvodbMb5p2ZMKqdlLeLFoSW1qcu33aRQTlt6NbiP_dkDO90DFO.pWGH"; AWS HTTP error: Client error: POST https://bucket-name.s3.amazonaws.com/NewProject.png?uploadId=nlWLdbNgB9zgarpLBXnj17eOIGAmQM_xyBArymtwdM71fhbFvveggDmL6fz4blz.B95TLhMatDvodbMb5p2ZMKqdlLeLFoSW1qcu33aRQTlt6NbiP_dkDO90DFO.pWGH resulted in a 400 Bad Request response: InvalidPartOne or more of the specified parts could not be found. The part may not have be (truncated...) InvalidPart (client): One or more of the specified parts could not be found. The part may not have been uploaded, or the specified entity tag may not match the part's entity tag. - InvalidPartOne or more of the specified parts could not be found. The part may not have been uploaded, or the specified entity tag may not match the part's en"

我找到了 PHP 等价物。

$command = $client->getCommand('UploadPart', [
    'Bucket'        => 'the-bucket-name',
    'Key'           => $key,
    'PartNumber'    => $partNumber,
    'UploadId'      => $uploadId,
    'Body'          => '',
]);

$presignedUrl = $client->createPresignedRequest($command, '+20 minutes');
$presignedUrlString = (string)$presignedUrl->getUri();