从邮递员发送照片没有问题。
标题是--->'Content-Type':'application / x-www-form-urlencoded'
body是----> form-data,{file:image ..}
发送标头到x-www-form-urlencoded或多部分/表单数据不起作用。
(HTTP状态400 –错误请求)
请注意,API中没有图像容量限制。请查看屏幕截图以了解更多邮递员。
我整夜呆了几天。请帮助我。...
用我的代码
let localUri = this.state.image; // <--- is image uri.
let filename = localUri.split('/').pop();
let match = /\.(\w+)$/.exec(filename);
let type = match ? `image/${match[1]}` : `image`;
let formData = new FormData();
formData.append('photo', { file: localUri, name: filename, type: type });
return fetch(MY_SERVER, {
method: 'POST',
body: formData,
headers: {
'Content-Type':'application/x-www-form-urlencoded'
},
}).then((response) => response.text())
.then((responseData) => {
console.log(responseData);
console.log('file',formData)
})
.done();
错误消息中我认为找不到名为file的密钥。这是API问题吗?
HTTP Status 400 – Bad Request
Required request part 'file' is not present
我认为错误在于此行代码:
formData.append('photo', { file: localUri, name: filename, type: type });
而不是尝试附加如下内容:
formData.append('file', localUri);
formData.append('name', filename);
formData.append('type', type);