django - DRF file.read() contains HTML header info and not just file content -


i'm not sure problem is, file.read() should give me file content. i'm printing out first 200 chars , content headers instead of uploaded file data.

uploader

local_file = os.path.join(basedir, 'a.jpg') url = baseurl + 'a.jpg' files = {'file': open(local_file, 'rb')} headers = {'authorization': 'token sometoken'} r = requests.put(url, files=files, headers=headers) print(r.status_code) 

view

class fileuploadview(baseapiview):     parser_classes = (fileuploadparser,)      def put(self, request, filename):         file_obj = request.files['file']         data = file_obj.read()         print(data[:200])         return response(status=http_204_no_content) 

and output printed is:

b'--139822073d614ac7935850dc6d9d06cd\r\ncontent-disposition: form-data; name="file"; filename="a.jpg"\r\n\r\n\xff\xd8\xff\xe0\x00\x10jfif\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xe1!(exif\x00\x00ii*\x00\x08\x00\x00\x00\r\x00\x0b\x00\x02\x00\r\x00\x00\x00\xaa\x00\x00\x00\x00\x01\t\x00\x01\x00\x00\x00x\x03\x00\x00\x01\x01\t\x00\x01\x00\x00\x00\xe8\x03\x00\x00\x0f\x01\x02\x00\x04\x00\x00\x00htc\x00\x10\x01\x02\x00\x0b\x00\x00\x00\xb8\x00\x00'

how come see data , not file content? dis has been driving me bonkers , going simple.

with fileuploadparser need send file content data

with open(local_file, 'rb') fh:     r = requests.put(url, data=fh, headers=headers, verify=false) 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -