PUT request to download a file not working in Flask

I am working on a web application using Flask. It is assumed that one of the views should accept downloaded files through PUT requests, but I can receive POST requests with the $ curl -F upload=@filename URL to work correctly. With PUT requests such as $ curl --upload-file filenname URL , request.files ImmutableMultiDict is empty. Am I missing something in Flask or perhaps using curl?

+6
source share
1 answer

The PUT request is different from the POST request. With a PUT request, access to the contents of the file can be obtained using request.data or request.stream . The first stores incoming data as a string, and request.stream acts more like a file object, which makes it more suitable for binary data:

 with open('uploaded_image.jpg', 'w') as f: f.write(request.stream.read()) 
+6
source

Source: https://habr.com/ru/post/909817/


All Articles