views:

158

answers:

1

Hi,

I want to enable the user to upload media which will not be saved in the media folder. When I use the following line of code data will be uploaded to media/upload/logo .

logo_img = models.FileField(upload_to='upload/logo', blank=True)

I'm wondering how I can change this behaviour.

I would try to write a custom FileField and a view that serves the data based on the database entries. I do not want to place the data the user uploads to the media folder, since it is no public data.

Is this approach correct? Are there solutions out there which do exactly what I want and I would reinvent the wheel with implementing this by myself?

Would appreciate any help!

+1  A: 

According to django's documentation, the default behavior for FileField is uploading files to MEDIA_ROOT. If you just want to keep the uploaded files private, you could separate the MEDIA_ROOT dir and the dir contains your site media files. And write a custom view to serve files from MEDIA_ROOT.

If you have more complex needs, you can implement your own file storage. Check http://docs.djangoproject.com/en/dev/howto/custom-file-storage/ for more information. With the custom file storage, you have full control of how the file is stored and how the file is served.

adieu
thanks, custom-file-storage was exactly what I was searching for!
Tom Tom