gpt4 book ai didi

react-native - 在 native react 中将图像转换为 base64

转载 作者:行者123 更新时间:2023-12-04 00:25:40 25 4
gpt4 key购买 nike

我使用了 react-native-image-picker,现在我从照片库中选择图像。要将图像发送到 API,我必须先将其转换为 base64,然后再转换为字节数组。我在 response.uri 中有文件路径。我该怎么做?
当我做 console.log(response) 我得到这个结果

'Response = ', {
fileSize: 6581432,
longitude: -17.548928333333333,
uri: 'file:///Users/shubhamb/Library/Developer/CoreSimulator/Devices/B58314DF-F0A9-48D2-B68A-984A02271B72/data/Containers/Data/Application/63143214-8A03-4AC8-A79C-42EC9B82E841/tmp/2AACBC57-0C07-4C98-985E-154668E6A384.jpg',
fileName: 'IMG_0003.JPG',
latitude: 65.682895,
origURL: 'assets-library://asset/asset.JPG?id=9F983DBA-EC35-42B8-8773-B597CF782EDD&ext=JPG',
type: 'image/jpeg',
height: 2002,
width: 3000,
timestamp: '2012-08-08T18:52:11Z',
isVertical: false,
}

最佳答案

由于您使用的是 react-native-image-picker ,它已经在其响应中返回 Base64 值

ImagePicker.showImagePicker(options, (response) => {
const base64Value = response.data;
});

Documentation for the response

关于react-native - 在 native react 中将图像转换为 base64,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57212109/

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