I keep getting a 422 error on my upload-csv-file request for some reason. I’m not sure why. I’m trying to upload a customer uploaded csv file to s3:
here is my frontend:
if (csvFile) {
let fd = new FormData();
fd.append("file", csvFile);
await post('/candidate/upload-csv-file', fd, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
}
here is the backend:
@router.post("/candidate/upload-csv-file")
async def create_upload_file(file: UploadFile = File(...)):
with tempfile.TemporaryDirectory() as temp_dir:
with open(f"{temp_dir}/{file.filename}", "wb") as tmp:
content = await file.read() # async read
tmp.write(content)
timestamp = int(time.time())
csv_imports_datastore = Datastore("csv_imports_cloud", db="heymilo_platform")
object_name = f"csv/entry_{'posting_id'}_{timestamp}.csv"
s3_url = svc_cloud_upload.upload_file(tmp.name, object_name=object_name,
content_type="text/csv")
if not s3_url:
raise Exception("Failed to upload file to S3")
csv_metadata = {
"posting_id": 'posting_id',
"s3_url": s3_url,
"timestamp": datetime.now(),
"timestamp_unix": time.time()
}
csv_imports_datastore.collection.insert_one(csv_metadata)
return {
"filename": s3_url
}
Here is the error:
{
"detail": [
{
"loc": [
"body",
"file"
],
"msg": "field required",
"type": "value_error.missing"
}
]
}
I’m trying to isolate if this is a backend/frontend issue, or something else. The payload is empty in the request:
empty payload
I tried on postman but get the same 422 error.
New contributor
Harshil Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.