开发者

django handling file uploads - target different than media folder

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 开发者_StackOverflowto 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜