我是新的网站开发。我使用React Redux和Python作为后端(Falcon框架),我所做的是:
1)从前端接收一个formData(),使用Dispatch-to-POST:
我的派遣代码:this.props.dispatch({type: ActionTypes.FILE_UPLOAD_REQUEST, email: this.state.email, file: this.state.policyFile});
并且使用中间件,只调用函数POST:
^{pr2}$
以及我的fetch函数:export const uploadFile = (email, file) => {
console.log(file);
return fetch(`${BASE_URL}/v1/files/${email}/policies`, {
method: 'POST',
body: file,
headers:{}
})
.then(response => response.json())
}
以及我的后端,使用falcon API:def on_post(self, req, resp, email):
local_path = create_local_path(req.url, req.content_type)
with open(local_path, 'wb') as temp_file:
body = req.stream.read()
temp_file.write(body)
问题是创建了temp_文件,但它已损坏,并且在我将扩展名更改为txt文件之后。它应该用一些只有计算机才能理解的奇怪代码编写。但是有些行会使整个文件损坏。请帮忙。以下是txt文件:------WebKitFormBoundaryQXmL1AgwA112xzkA
Content-Disposition: form-data; name="file"; filename="baboon.jpg"
Content-Type: image/jpeg
ˇÿˇ‡JFIFˇ€Ñ ( %!1"%)+...383-7(-.+
在
-%---------------.-------------------------7-----
“啊”啊;!1AQ“aqë”2BR-······················!QAA“Š2Bq⁄”?“克÷=`^-
Á÷美元ìxıxÄÅ5kÔW¶ÈK@“tq]~¸,J^dö“≈B–Ba.'QoQ∏0dúC•,nı^⁄1BR,ò
Ô⁄XΩ-Eb&;
继续前进
看前3行,它使文件损坏。在
有什么想法吗?在