我正在尝试将设备中的图像直接上传到s3。我能够读取图像元数据并将其发送到服务器,以便为aws s3生成预签名的url。我也有预签名的url,我想使用axios
上传文件/图像,但不知何故图像/文件无法上传。这是我的代码。
图像数据(由ImagePicker读取)
data: "" // image raw data
fileName: "acx.jpg"
fileSize: ""
uri: ""
path: ""
用于将所选图像发送到aws s3的代码。
const options = { headers: { 'Content-Type': fileType}};
axios.put(res.data.signedRequest, data , options);
我得到了下面的回复。
res = {
config:
data: ""
status: 200
StatusText: undefined
...
}
那么,我应该在axios
请求中传递什么数据呢?
发布于 2019-06-06 09:44:52
你探索过这个plugin吗?这将使这一过程变得容易得多。然后你可以试着
upload = () => {
const file = {
uri: this.state.imageuri,
name: acx.jpg,
type: "image/jpeg"
};
const options = {
keyPrefix: "ts/",
bucket: "celeb-c4u",
region: "eu-west-1",
accessKey: "AKIAI2NHLR7A5W2R3OLA",
secretKey: "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",
successActionStatus: 201
};
return RNS3.put(file, options)
.then(response => {
if (response.status !== 201)
throw new Error("Failed to upload image to S3");
else {
console.log(
"Successfully uploaded image to s3. s3 bucket url: ",
response.body.postResponse.location
);
this.setState({
url: response.body.postResponse.location
});
}
})
.catch(error => {
console.log(error);
});
};
https://stackoverflow.com/questions/56469385
复制相似问题