Flask FileStorage object to File Object
Answer a question
I have made an api through flask which submit a file and after receiving it on the back end , I want to further upload this to an unknown server using python requests module
The server accepts the file if I do this like -
requests.post(urlToUnknownServer,files={'file':open('pathToFile')})
Now my requirement is to get the file param uploaded through flask.
In flask I get the file as FileStorage object. I don't want to save this on my server, instead directly wants it to upload further.
So basically I want to convert that FileStorage object to return type of open() function which is file(please correct me here if I am wrong)
I had tried it using -
obj=file(request.files['fileName'].read().encode('string-escape'))
requests.post(urlToUnknownServer,files={'file':obj})
This doesn't work. Can it be possible to do that without saving file on my server.
Answers
Maybe you can use read() without encoding it. such as this:
obj=request.files['fileName'].read()
requests.post(urlToUnknownServer,files={'file':obj})
更多推荐

所有评论(0)