1

我正在尝试使用signed url. 我正在生成url,使用JAVA如下方法(在此链接的帮助下):

public String generatePutObjectSignedUrl(String bucketName, String objectName, String contentType) throws GenericAttachmentException {
        if (!bucketExists(bucketName)) {
            createBucket(bucketName);
        }
        // Define resource
        BlobInfo blobInfo = BlobInfo.newBuilder(BlobId.of(bucketName, objectName)).build();

        // Generate signed URL
        Map<String, String> extensionHeaders = new HashMap<>();
        extensionHeaders.put("Content-Type", contentType);

        return String.valueOf(storage.signUrl(
                blobInfo,
                15,
                TimeUnit.MINUTES,
                SignUrlOption.httpMethod(HttpMethod.PUT),
                SignUrlOption.withExtHeaders(extensionHeaders),
                SignUrlOption.withV4Signature()));

    }

我也得到了一个上传网址,如下:

https://storage.googleapis.com/bucket/43fb114d-973e-4157-8a3d-0d479aa5b255/1553.pdf?X-Goog-Algorithm=GOOG4-RSA-SHA256&X-Goog-Credential=storage-dev%40project-name-229712.iam.gserviceaccount.com%2F20200622%2Fauto%2Fstorage%2Fgoog4_request&X-Goog-Date=20200622T181856Z&X-Goog-Expires=900&X-Goog-SignedHeaders=content-type%3Bhost&X-Goog-Signature=27de4c5f8f669ead91cdf2a3cf91485ac272be5357420dc40d75a534834ed300d19098f857c638558624b4500762820002fa99071f35723146c4afca01d5b77f56c90fa63b53598b887d71ef7a49b2bb389ce70bcee11db9f5cff6f6164e9821753ae82651379138b12b46c82c0fee3d8898b45a4b06fd80925a501d036289093fcb94226cfdecd285991ea2a215577321ffc1c1d5f30bfe0e83c1b876351e87240cf17eb940fdb91d813cb8b7988ce09f71e51464728ac58e3d8fdd8d3bb5a279791d87069fc8d3719ad2080886ff931f00e3691fbe85df3f503ab9175da2d5b7d65c3d3412a3f8f9446164682e17dcf64942fa6d2c30a2e173438e186221d5

但是,当我尝试在上述 URL 上使用 HTTP PUT 上传对象时,使用POSTMAN,我收到以下错误:

<?xml version='1.0' encoding='UTF-8'?>
<Error>
    <Code>SignatureDoesNotMatch</Code>
    <Message>The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.</Message>
    <StringToSign>GOOG4-RSA-SHA256
20200622T181856Z
20200622/auto/storage/goog4_request
086bc1e8dfe17975d9c67a59edcaf003a26631a2451b82a370b0bbaf0a8003be</StringToSign>
    <CanonicalRequest>PUT
/bucket/43fb114d-973e-4157-8a3d-0d479aa5b255/1553.pdf
X-Goog-Algorithm=GOOG4-RSA-SHA256&amp;X-Goog-Credential=storage-dev%40project-name-229712.iam.gserviceaccount.com%2F20200622%2Fauto%2Fstorage%2Fgoog4_request&amp;X-Goog-Date=20200622T181856Z&amp;X-Goog-Expires=900&amp;X-Goog-SignedHeaders=content-type%3Bhost
content-type:multipart/form-data; boundary=--------------------------707205682373848354360690
host:storage.googleapis.com

content-type;host
UNSIGNED-PAYLOAD</CanonicalRequest>
</Error>

这是一个真正难以破解的难题。非常感谢一些帮助。

4

0 回答 0