-1

When a user logs into the database, he generates a WAV audio file (in the browser) which has to be stored in the database. The problem is that, everything is fine when I store the file for the first time. But, when I store after that, I get IntegrityError. Does anyone have the solution to this?

My current models.py is the following:

class InputFile(models.Model):

audio_file = models.FileField(upload_to='audio_files')
input_user = models.ForeignKey(User)
rec_date = models.DateTimeField('date recorded', auto_now_add=True)
CuriousCoder
  • 491
  • 5
  • 9
  • Your question is answered here: http://stackoverflow.com/a/13333478/202168 – Anentropic Jul 22 '14 at 13:27
  • Is your question about directly storing the files in the database as a blob? It is strongly discouraged for many reasons http://www.revsys.com/blog/2012/may/01/three-things-you-should-never-put-your-database/ – arocks Jul 22 '14 at 13:28
  • @Anentropic I had seen that post before, but I wanted to know whether I can exploit the features in Django framework itself. – CuriousCoder Jul 22 '14 at 13:43
  • @arocks my final aim is to store as a WAV file (which I guess can be converted from blob) – CuriousCoder Jul 22 '14 at 13:44
  • as far as Django is concerned you're just uploading a file... the part you seemed stuck with is how to upload a javascript blob rather than an field – Anentropic Jul 22 '14 at 13:47

1 Answers1

-1

I would still recommend storing the user media as files. This way you can avoid storing large files in the database which is not only inefficient but also slow.

Furthermore, I would not recommend performing audio processing within the Django request-response. Try to use an asynchronous solution like Celery.

Audio processing is quite similar to Video processing. You can get a lot of ideas from how video sharing sites like YouTube work. Once you upload a file, they notify you when the uploading and encoding is completed. This happens in a separate task queue.

The intermediate and final media files are again stored as files and served directly from the filesystem. By avoiding the database layer you can get a much more responsive application.

arocks
  • 2,862
  • 1
  • 12
  • 20