10

I have a C# program that inserts a pdf inside a MySQL database. Now I want to retrieve that pdf via django but django's models.FileField needs an "Upload To" parameter which means behind the scenes it actually stores the File on the file system rather than in the database. Is there any way I can set up a django model so that I can store the pdf directly inside MySQL?

Regards

Mechanical snail
  • 29,755
  • 14
  • 88
  • 113
RaVen
  • 775
  • 2
  • 8
  • 21

2 Answers2

16

Just as an update to this, as of Django 1.6, there's now a BinaryField option that will store files up to 4 GB in size. https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.BinaryField

Kevin London
  • 4,628
  • 1
  • 21
  • 29
1

I have been dealing with this same issue, writing a pdf to a mediumblob field in mysql and retrieving via django. I have set the mysql field type to a mediumblob and the django field type to textfield. I have used a queryset and httpresponse to view the PDF objects in a browser (but not directly in django).

Joseph
  • 290
  • 5
  • 15
  • I did try the same and it felt very hacky and not in the nature of django. So I used PHP for the project instead. Like they say use the right tool for the right job! Storing data in blob fields especially in web development is frowned upon. But sometimes you HAVE to do it! =) – RaVen Aug 19 '11 at 07:05