![](/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.