Django audio recorder Bad request: /record-audio/

53 views
Skip to first unread message

Yong Zu Yi

unread,
Mar 27, 2023, 11:00:27 PM3/27/23
to Django users
I am now making a audio journaling application, and I will need a recorder in Django. But I receive a error Bad request.
code.JPG
I have add some print statement to see where is having problem. and it shows me <QueryDict: {}>
error.JPG
Can somebody help me!

I have posted the rest of the code in stack overflow because the code is toooo long:

Tega Ukavwe

unread,
Mar 28, 2023, 3:53:11 AM3/28/23
to django...@googlegroups.com

Hi Yong Zu Yi,

Based on the screenshot you provided, it looks like you're trying to retrieve an audio file from the request's POST data using the request.POST dictionary.

However, audio files should be sent as part of the request's FILES data, not POST data.

To retrieve the audio file from the request's FILES data, you should use the request.FILES dictionary instead.

I have attached a screenshot of a modified code, I first check if the audio file is present in the request.FILES dictionary. If it's not present, I simply return a 400 Bad Request response. If it's present, create a filename based on the current user's username and the current date and time, and save the audio file to the server using the open function and a for loop to write the file in chunks.

I hope this helps you solve the issue you were facing. Let me know if you have any further questions.


Best Wishes,

Tega Ukavwe

Python Like English

Screenshot 2023-03-28 at 08.47.41.png

Tega Ukavwe

unread,
Mar 28, 2023, 4:11:48 AM3/28/23
to django...@googlegroups.com
Apologies, the previous solution has a mistake in it, on line 27.

Kindly refer to the attached screenshot.

Thanks,
Tega Ukavwe
Python Like English
Screenshot 2023-03-28 at 08.47.41.png

Tega Ukavwe

unread,
Mar 28, 2023, 4:18:54 AM3/28/23
to django...@googlegroups.com
I am currently neck-deep in work, I made the mistake of sending the incorrect screenshot.
I have corrected it, kindly view the screenshot attached to this email instead.
Thanks for understanding.

Many Thanks,
Tega Ukavwe
Python Like English
Screenshot 2023-03-28 at 09.07.34.png

Yong Zu Yi

unread,
Mar 28, 2023, 5:21:09 AM3/28/23
to Django users
Thank you for replying me. However, I still get the error Bad request: /record-audio/.

Also, I have a question, is it possible that after recording, it will just save to the database? Because what I have found that the only way to save media files into database is to upload it.

Thanks!

error2.JPG

Yong Zu Yi

unread,
Mar 28, 2023, 7:23:37 AM3/28/23
to Django users
The screenshot below is related to the code for audio recording.

chat_script.html
chat_script.png

record.html
record.png

Thanks!

Yong Zu Yi

unread,
Mar 28, 2023, 7:29:44 AM3/28/23
to Django users
chat_script.png
I am sorry, I think this would be better for chat_script,html.

Thank you so much!


Reply all
Reply to author
Forward
0 new messages