我正在使用 Expo Image Picker 将裁剪后的图像发送到 s3。该文件正在上传,但它不会呈现为图像,因为它未被识别为图像。如果我使用 blob 数据并在 base64 图像编码器中使用它,我会得到图像,所以它必须是基于 mime 或编码的,这就是我所拥有的。
我调用 Expo Image Picker ;
let pickerResult = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
aspect: [1, 1],
base64: true,
exif: false,
});
我用来从 s3 SDK 创建签名 URL 的参数是;
const params = {
Bucket: 'images,
Key: 'filename.jpg',
Expires: 60 * 5,
ACL: 'public-read',
ContentEncoding: 'base64',
ContentType: 'image/jpeg'
};
上传是使用带有以下标题的 axios 完成的;
const config = {
headers: {
'x-amz-acl' : 'public-read',
'Content-Encoding': 'base64',
'Content-Type': 'image/jpeg'
}
};
return await axios.put(`${signedURL}`,
base64data,
config)
.then(response => {
console.log('IMAGE UPLOAD SUCCESS');
return response.data;
})
如果我将创建的 .jpg 文件更改为 .txt 并在 sublime 中查看它,则数据是 base64 编码的字符串,而不是 jpeg 的常用 blob 数据。
我究竟做错了什么?