jdhao / jdhao.github.io

My personal blog: https://jdhao.github.io/
25 stars 6 forks source link

2020/04/12/build_webapi_with_flask_s2/ #90

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Build Web API with Flask -- Post and Receive Image - jdhao's digital space

In this post, I want to write about how to build a simple image processing web API that returns the size of an image. The topics include how to build this web API with Flask and how to post image to this web API and get response.

https://jdhao.github.io/2020/04/12/build_webapi_with_flask_s2/

romanvelichkin commented 1 year ago

files = request.files.to_dict(flat=False) ## files is a list containing two images. for i, file in enumerate(files): file.save(f'image-{i}.jpg')

This way files will look like {'image': [<FileStorage: 'test.jpg' (None)>, <FileStorage: 'test.jpg' (None)>]}, so parsing it with loop won't return files from request.

Correct way to set files is files = request.files.to_dict(flat=False)['image'].

romanvelichkin commented 1 year ago

r = requests.post(url, files=multiple_files, data=data)

Also data is not set in code, so this row will rise an error.

romanvelichkin commented 1 year ago

Thank for this post! It really helps - simple and useful.