1
  1. Upload a tar file.

  2. How to get the file object in request.data?

class AlbumViewSet(viewsets.ModelViewSet): @action(methods=['POST'], detail=False, url_path='upload-album') def upload_album(self, request): # Upload one tar file. logging.error("----> request.data = {}".format(request.data)) 

Thanks

1 Answer 1

2

You can get file object in request.FILES.
request.FILES is dictionary like object containing all uploaded files. You can access your file object by its name, like this: request.FILES['my-file-name']

For example, if you want to log filename::

class AlbumViewSet(viewsets.ModelViewSet): @action(methods=['POST'], detail=False, url_path='upload-album') def upload_album(self, request): # Upload one tar file. logging.error("----> Uploaded file name = {}".format(request.FILES['my-file-name'].name)) 

Check here for more details.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. But when I print the request.FILES, you can see that it is <MultiValueDict: {}> [Print Log] root:----> request.FILES --> = <MultiValueDict: {}>
Thanks, I find the answer finally. I should to upload file by Multipart/form-data.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.