File posting via RESTful api with django and tastypie

前端 未结 2 686
别跟我提以往
别跟我提以往 2021-02-08 16:28

i am creating an RESTful api for a Django website. I am using tastypie for doing it. My problem is i could\'nt design how to post images or files via this api. I mean, to create

2条回答
  •  既然无缘
    2021-02-08 16:48

    Serializing the file into the JSON request is a slightly awkward way to do things, and also is going to mean you lose some of Django's file upload automatic niceness, eg writing the file to memory as the request comes in, and only switching to writing it to disk once it gets above a certain size.

    For the file upload view you might want to drop out of tastypie, and write the view explicitly.

    Then you could either use a standard multipart form, (and just access the file using request.FILES as usual, or (more complicated), create a view that will accept the raw file content.

提交回复
热议问题