Angular to Django - 'Unknown string format:'
I am building a front end using Angular where the user selects a file and a date (using a date picker). This is then sent to django using the django_rest_framework to to a standalone class that uploads this file onto an oracle database using sqlalchemy.
The uploading page use to work fine when it was created on a Django template, however I need to migrate this to angular and when i pass the file and date parameters i get an error:
Error: ('Unknown string format:', 'Tue Dec 07 2021 00:00:00 GMT+0000 (Greenwich Mean Time)')
Where Tue Dec 07 2021 00:00:00 GMT+0000 (Greenwich Mean Time) represents the date chosen from the datepicker.
Anyone know why this is happening?
views.py
@api_view(('POST',))
@csrf_exempt
def uploader(request):
if request.method == 'POST':
try:
instance= uploader(request.FILES['data'], request.POST['selectedDate'])
_ = upload_instance.run_upload_process('data')
upload_message = "Success"
return Response(upload_message, status=status.HTTP_201_CREATED)
except Exception as e:
upload_message = 'Error: ' + str(e)
return Response(upload_message, status=status.HTTP_400_BAD_REQUEST
upload.component.ts
onFileChange (event:any) {
this.filetoUpload = event.target.files[0];
}
inputEvent(event:any) {
this.monthEndDate = event.value;
}
newUpload() {
const uploadData = new FormData();
uploadData.append('data', this.filetoUpload, this.filetoUpload.name);
uploadData.append('selectedDate', this.monthEndDate)
this.http.post('http://127.0.0.1:8000/upload/', uploadData).subscribe(
data => console.log(data),
error => console.log(error)
);
}