将视频从React本机上传到AWS Signed网址时出现SignatureDoesNotMatch错误

时间:2020-07-23 14:53:36

标签: javascript ios react-native amazon-s3

我正在尝试将视频上传到从Brightcove生成的S3签名的url中。我拥有的代码可以在Android上使用,但不能在iPhone上使用,它会返回:

<?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 key and signing method.</Message><AWSAccessKeyId>ACCESS_KEY</AWSAccessKeyId><StringToSign>PUT

video/mp4
1595593499
/ingestion-upload-production/6156229735001/6174315892001/d7885428-be54-483d-8033-b2ae1c6f2ccc/influencer-2.mp4</StringToSign><SignatureProvided>Xm1W67u+mpFF5cIZZZ1Zgf8SD0U=</SignatureProvided><StringToSignBytes>50 55 54 0a 0a 76 69 64 65 6f 2f 6d 70 34 0a 31 35 39 35 35 39 33 34 39 39 0a 2f 69 6e 67 65 73 74 69 6f 6e 2d 75 70 6c 6f 61 64 2d 70 72 6f 64 75 63 74 69 6f 6e 2f 36 31 35 36 32 32 39 37 33 35 30 30 31 2f 36 31 37 34 33 31 35 38 39 32 30 30 31 2f 64 37 38 38 35 34 32 38 2d 62 65 35 34 2d 34 38 33 64 2d 38 30 33 33 2d 62 32 61 65 31 63 36 66 32 63 63 63 2f 69 6e 66 6c 75 65 6e 63 65 72 2d 32 2e 6d 70 34</StringToSignBytes><RequestId>34038BC3772C8E20</RequestId><HostId>VgjsNXg9r8gGLvhF5Pwa+2d9D61BTTMZtu/SsUKwzkdz2RZORN69AQp7isqQ3un7Z9h105Lz5vU=</HostId></Error>

这是我的代码:

    const preSignedURL =
        'XXXX';


    let imagePATH = p.node.image.uri;
    if (Platform.OS === 'ios') {
        const photoPATH = convertLocalIdentifierToAssetLibrary(
            p.node.image.uri,
            'MP4',
        );

        const dest = `${RNFS.TemporaryDirectoryPath}influencer-2.mp4`;

        imagePATH = await RNFS.copyAssetsVideoIOS(
            photoPATH,
            dest,
        );
    }

    const headers = { 'Content-Type': 'video/mp4' };

    imagePATH = imagePATH.replace('file://', '');

    RNFetchBlob.fetch(
        'PUT',
        preSignedURL,
        headers,
        RNFetchBlob.wrap(imagePATH),
    )
        .then((res) => {
            const { status } = res.info();
            console.log(res.info());
            console.log(res.text());
            console.log(res.base64());
            if (status === 200) {
                console.log(res.text());
            } else {
                // handle other status codes
            }
        })
        // Something went wrong:
        .catch((errorMessage, statusCode) => {
            console.log(errorMessage);
        });
}}  

我也尝试过使用xhr或fetch,但是我总是遇到相同的错误。我知道问题可能出在其他标头或其他内容上,但这在Android系统中效果很好

0 个答案:

没有答案