Skip to content
Snippets Groups Projects
Commit 1e4f3404 authored by Neda Moeini's avatar Neda Moeini
Browse files

Update encoding on reading CSV files to cover Windows user as well

parent 32d021ae
No related branches found
No related tags found
No related merge requests found
...@@ -76,7 +76,7 @@ class CSVUploadForm(forms.Form): ...@@ -76,7 +76,7 @@ class CSVUploadForm(forms.Form):
self._validate_file_type(file) self._validate_file_type(file)
# Step 2: Parse file and validate headers # Step 2: Parse file and validate headers
raw_data = file.read().decode("utf-8") raw_data = file.read().decode("utf-8-sig")
normalized_data = raw_data.replace("\r\n", "\n").replace("\r", "\n") normalized_data = raw_data.replace("\r\n", "\n").replace("\r", "\n")
csv_file = normalized_data.splitlines() csv_file = normalized_data.splitlines()
reader = csv.DictReader(csv_file, delimiter=",") reader = csv.DictReader(csv_file, delimiter=",")
......
...@@ -53,7 +53,7 @@ class CSVUploadAPIView(APIView): ...@@ -53,7 +53,7 @@ class CSVUploadAPIView(APIView):
csv_file = form.cleaned_data["file"] csv_file = form.cleaned_data["file"]
csv_file.seek(0) csv_file.seek(0)
decoded_file = csv_file.read().decode("utf-8").strip() decoded_file = csv_file.read().decode("utf-8-sig").strip()
if not decoded_file: if not decoded_file:
return Response({"status": "error", "message": "Uploaded file is empty."}, return Response({"status": "error", "message": "Uploaded file is empty."},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment