![](/img/trans.png)
[英]React Native: fetch request failed with error - TypeError: Network request failed(…)
[英]React Native send data on android [Type Error: Network request failed]
我正在尝试从android图像库中获取图片并将其保存在我的cloudinary帐户中。 我使用axios / fetch并收到错误“网络请求失败”。 下面是我的代码:
_pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
aspect: [4, 3],
});
let formData = new FormData();
formData.append("file", result);
formData.append("tags", 'text_detection');
formData.append("upload_preset", "xxx");
formData.append("api_key", "xxx");
if (!result.cancelled) {
this.setState({ image: result.uri });
}
return fetch("http://api.cloudinary.com/v1_1/ebrugulec/image/upload", {
headers: {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data'
},
method: 'POST',
body: formData
}).then(function(response){
return response.json();
}).catch(function(error) {
console.log('There has been a problem with your fetch operation: ' + error.message)
})
};
}
您正在尝试使用Cloudinary REST API上传但没有签名。 您应该在上传请求上签名,并将签名添加为上传参数的一部分。
如何生成签名: https : //cloudinary.com/documentation/upload_images#generating_authentication_signatures
这是一个代码示例: https : //github.com/cloudinary/cloudinary_npm/issues/145#issuecomment-406852031
相反,您可以使用Cloudniry SDK轻松上传图像。
--Yakir
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.