Getting A Typeerror: Expected Str, Bytes Or Os.pathlike Object, Not Inmemoryuploadedfile
def post(self, request): form = CsvUploadForm(request.POST, request.FILES) if form.is_valid(): with open(request.FILES['csv']) as csv_source: has_heade
Solution 1:
As @ Daniel Roseman
said, you can directly use the filestream as ,
def post(self, request):
form = CsvUploadForm(request.POST, request.FILES)
if form.is_valid():
reader = csv.DictReader(request.FILES['csv'])
....
....
return HttpResponse("file Uploaded")
Solution 2:
Try reading the request into a BytesIO stream, then perform your operations on that object.
def post(self, request):
form = CsvUploadForm(request.POST, request.FILES)
if form.is_valid():
csv_source = BytesIO(request.FILES['csv'].read())
has_header = csv.Sniffer().has_header(csv_source.read(1024))
csv_source.seek(0)
reader = csv.DictReader(csv_source)
....
....
return HttpResponse("file Uploaded")
Post a Comment for "Getting A Typeerror: Expected Str, Bytes Or Os.pathlike Object, Not Inmemoryuploadedfile"