gpt4 book ai didi

react-native - react native 缺少 readAsArrayBuffer

转载 作者:行者123 更新时间:2023-12-02 21:49:49 24 4
gpt4 key购买 nike

我正在尝试将uri图像(使用react-native-image-picker检索)转换为数组缓冲区以将文件上传到s3(因为s3不支持我无法使用的放置请求的表单数据它)

这是我的代码

    let fetched = await fetch(pictureInfo.uri)
console.log("Fetched uri:", fetched)
let arrayBuffer = await fetched.arrayBuffer()

但是运行它我收到

Error: FileReader.readAsArrayBuffer is not implemented

如何将其转换为缓冲区并上传到 s3,而不将其转换为 base64?

最佳答案

无需使用base64方法,您可以直接使用react-native-fetch-blob包上传图像文件。

假设您有用于 react-nativeaws-sdk

// Add Config

AWS.config.update({
region: // Your Region,
accessKeyId: // Your Access key,
secretAccessKey: // Your Secret Key,
sessionToken: // Your Session Token,
});

// Initialize
const s3 = new AWS.S3();

// Get Signed Url
const signedUrl = await s3.getSignedUrl('putObject', {
Bucket: // Your Bucket,
Key: // Your Key,
ContentType: // Content Type, example `image/jpg`,
});


const s3 = new AWS.S3();

const upload = await RNFetchBlob.fetch('PUT', signedUrl, {
'Content-Type': // Content Type
}, RNFetchBlob.wrap(localPath)); // where local path would be your local image path ${image.uri}

关于react-native - react native 缺少 readAsArrayBuffer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49680483/

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