我想将我的应用程序中的图像上传到S3服务器.我已经计算了所有数据和代码(在计算机上使用curl测试),但我无法弄清楚如何正确调用'fetch'.我得到回应:
'您指定的至少一个前提条件不成立.条件:Bucket POST必须是enclosure-type-multipart/form-data'
如何在react-natives fetch中重新创建表单数据?没有我可以附加的FormData,然后像在fetches示例中一样发送它.
编辑:谢谢@ philipp-von-weitershausen,请注意您已添加此功能.但是我有一些麻烦叫它.我得到"不支持的BodyInit类型".发现那是因为在fetch.js中:"support.formData"返回false.我打电话给fetch时我错过了什么?
我的代码示例:
var form = new FormData();
form.append("FormData", true)
form.append("name", this.state.invoiceNumber)
form.append("key", this.state.invoiceNumber)
form.append("Content-Type", "image/png")
form.append('file', this.props.uri)
//alert(FormData.prototype.isPrototypeOf(form))
fetch(amazon_url,{body: form,mode: "FormData", method: "post", headers: {"Content-Type": "multipart/FormData"}})
.then((response) => response.json())
.catch((error) => {
alert("ERROR " + error)
})
.then((responseData) => {
alert("Succes "+ responseData)
})
.done();
Run Code Online (Sandbox Code Playgroud)