When I upload a small file <25mb everything works as expected, when I upload a larger file >50mb the conditions and everything else works but my view doesn’t return the the response.
#views.py
if request.method=="POST":
serializer=UploadSerializer(data=request.data,context={"request":request})
if serializer.is_valid():
result=request.user.upload(serializer.validated_data['room'])
#the method is just checking some conditions it doesn't affect anything
if result is None:
serializer.save()
return Response(serializer.data,status=status.HTTP_200_OK)
else:
return Response(result,status=status.HTTP_403_FORBIDDEN)
else:
return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST)
#client side
async def upload(cmd_dict):
try:
f=await aiofile.async_open(cmd_dict['upath'],'rb')
except:
await printScreen("client_error","Invalid path, make sure to surround the path with double quotes \"\"")
else:
await printScreen("client_info",f"Uploading {os.path.basename(f.file.name)}")
try:
async with httpx.AsyncClient() as client:
res=await client.post(BASE_URL+"uploads/",data={
"room":room['id'],
"dname":cmd_dict['dname'] if cmd_dict['dname'] is not None else '',
'caption':cmd_dict['caption'] if cmd_dict['caption'] is not None else '',
},files={'file':(os.path.basename(f.file.name),await f.read())},headers=HEADERS)
await f.close()
except Exception as e:
print(e)
else:
print(res.text)
res_json=json.loads(res.text)
if res.is_success:
await printScreen("client_ok","File uploaded!")
ws.send(json.dumps({
"type":"chat",
"text":f"{res_json['file']} | {res_json['dname']}\n{res_json['caption']}"
}))
else:
print(res.text)
await printScreen("client_error",res.text)
#Most things don't matter here, cmd_dict is just a dictionary for checking the command the user inputted, printScreen is a custom method, and I have to use async due to the way my client works.
Below of this line is the output of the server from (top to bottom, uploading a small file, uploading a big file) (both intentionally will fail with error 400), one returns the response, the other doesn’t, I have checked with the print statement that the part below else does run, it’s just not returning the response.
small file:
Bad Request: /uploads/
HTTP POST /uploads/ 400 [0.02, 127.0.0.1:52527]
big file:
Bad Request: /uploads/
Edit : Incase you were wondering, it’s the same with the post request as well, and if I type a print statement above serializer.save() it run, but again, no response if it’s a big file.
And no it doesn’t have anything to do with the response’s content, I changed it from serializer.errors to a simple static text but the behavior is still the same.