9
9
95506682020-07-20 00:22:25
Django
9550668, 2020-07-20 00:22:25

How to download a file from a JSON request?

Hello. I will be grateful for help.

There is a JSON request to the server that passes a file in the body (I'm currently using Postman to test the API).

How can I edit this file and save it to the server? I found a lot of articles on the Internet using REST FRAMEWORK, but I would like to write a solution without using this library.

As I understand it, the file lies in self.request.FILES.get('image'), and even through print in the terminal the file name is displayed. What's next? Can you suggest?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-07-20
@bacon

As I understand it, the file lies in self.request.FILES.get('image'), and even through print in the terminal the file name is displayed.

So there you have the file data, https://docs.djangoproject.com/en/3.0/ref/files/up... this class has a read method that will return its contents. It remains to read the docks how to write something to a file in python.
Threat is a little confusing that you write "JSON that passes the file to body", but in fact you have request.FILES, these are two different ways.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question