How to send file&

hello
i trying to send file to my new endpoint, which look like this:

@v2.route(’/up_file’, methods=[‘GET’, ‘POST’])
def decode_watermark(request):
test = request.files
print(test)
return json({“ok”: “200”})
if i send file from postman, using application/x-www-form-urlencoded header and form-data field, i get {} in print()
can you explane,how can I get some file without download it in file system?

For example, i want to send image to sanic, getting EXIF and return it
Thanks!

Hi there,

Could you share how did you send a file with postman? I think your code snippet should work except that the request sends from postman is not a valid file upload request.

Here is an example that I use postman to send a image file:

As you can see, I did not set any header in this request.

And, to get EXIF from the uploaded image, you can save it to BytesIO and use PIL to read it, for example:

from sanic import Sanic
from sanic.response import text
from io import BytesIO
from PIL import Image

app = Sanic()


@app.post("")
async def get_image_exif(request):
    image = request.files.get("image")
    image = BytesIO(image.body)
    image.seek(0)

    image = Image.open(image)
    exif = image._getexif()

    return text(exif)