3

I have a csv file that I want to send via curl to a Django Rest Framework API View I have developed. The csv file itself contains only foo,bar and this is the curl command I'm using:

curl URL -H 'Accept: 
application/json' -H 'Referer: http://localhost:5011/ost:5011' -H 
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 
Safari/537.36' -H 'Authorization: JWT TOKEN  -H 'Content-Type: 
multipart/form-data' -F [email protected]

When it hits my API View in Django, and I run

request.data.get('file').read()

the output is some metadata around the file and not the file contents itself:

(Pdb) b'--------------------------001ec735bfc1a929\r\nContent-
Disposition: form-data; name="upload"; 
filename="testcsv.csv"\r\nContent-Type: application/octet-
stream\r\n\r\n\r\n--------------------------001ec735bfc1a929--\r\n'

How can I access the actual file itself through this method? My APIview is using

class FileUploadView(APIView):
     parser_classes = (MultiPartParser,)

Thanks!

1 Answer 1

1
f = request.FILES["filefield_name"]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.