after getting the uploaded file, write the uploaded file stream to the server file. The file contains more http
stream related information
--X-INSOMNIA-BOUNDARY
Content-Disposition: form-data; name="file"; filename="a.txt"
Content-Type: text/plain
Hello
--X-INSOMNIA-BOUNDARY--
how to get uploaded file information when saved, it will only be the original file.
< hr >add my source code:
class UploadView(APIView):
"""
"""
parser_classes = (FileUploadParser, )
def put(self, request, filename, format = None):
"""
"""
up_file = request.data["file"]
base_dir = settings.BASE_DIR
print filename
storage = base_dir + "/" + "storage/"
new_file = storage + up_file.name
with open(new_file, "wb+") as destination:
for chunk in up_file.chunks():
destination.write(chunk)
destination.close()
-sharp up_file.new_file("file", new_file, up_file.content_type, up_file.size, up_file.charset, up_file.content_type_extra)
-sharp with open(new_file, "wb+") as destination:
-sharp for line in up_file:
-sharp destination.write(line)
-sharp destination.close()
-sharp -sharp destination.write(up_file.multiple_chunks())
-sharp -sharp destination.close()
return Response(up_file.name, status.HTTP_201_CREATED)