Reputation: 30
When I am trying to post the file that I have received from a post request, it is giving me an error as:
expected str, bytes or os.PathLike object, not FileStorage
How am I suppose to post the file? A proper syntax is what I am looking for. However without posting file, that is only posting data is working fine.
from PIL import Image
from flask_restful import Resource, request, Api
import requests
class fileSendingApi(Resource):
def post(self):
images=open(request.files['my_image_1'],'rb')
URL = 'http://127.0.0.1:5000/final_img_api'
file={"my_image_2": images}
values={"auth_key": "some_auth_key"}
response = requests.post(URL, files=file, data=values)
output = response.json()
Upvotes: 0
Views: 100
Reputation: 131
You have a mistake in your code:
images=open(request.files['my_image_1'],'rb')
When using open you are actually transforming the file from web-uploaded file to FileStorage
.
What you want to do is use the file that was uploaded:
images=request.files['my_image_1']
and it should work.
By the way, if you want to save the image use: images.save(FILE_PATH)
instead of open()
Upvotes: 1