Mixing django-filepicker and mongodb - django

I'm developing a django 1.4 application, and I'm using django-filepicker to upload images. They use a special modelField for images called FPFileField.
I'm interested in storing those images in a MongoDB database, instead of uploading it to a "media" folder or something similar.
Any idea how this can be achieved?
I've tried mongoengine with no luck.

I would recommend storing the url into your mongo Document directly and then making use of the filepicker.io URL and built in S3 support rather than storing the file on your servers directly.

You should look into GridFS
I'd also consider uploading it to amazon's S3 service too - depending on what your requirements are.

Related

Migrating Django app to use online media storage

I have a Django app running on a server. Currently user uploads are stored on the server filesystem.
I already know how to set up S3 storage. What is the best way to migrate existing uploads to S3 without breaking the API and having existing uploads still available?
These files are served to the front end in two ways:
Directly through a /media/path/to/upload endpoint:
/media/<path> django.views.static.serve
Through a viewset:
/api/v1/users/<user_pk>/items/<item_pk>/attachments/<pk>/ project.app.views.ItemAttachmentsViewSet
Does the following make sense:
Change the storage backend
Go through all model objects
Save each model object to get the files uploaded
Have /media/path go to a new view that will serve the files similar to how ItemAttachmentsViewSet does it.
? Or is there a better way?
The procedure outlined in the question was what I ended up doing, with the exception of step 4 which turned out to be unnecessary.

Django: caching images

I am currently using django-compressor which provides great benefits by caching compressed CSS and JS files.
Now I would like to cache images. I know that browser caching can be enabled using HTTP headers (downstream caching) but I would like to use Redis here (it is already used by django-compressor).
So this is my first question: is it right to cache images with Redis?
I have read interesting things about sorl-thumbnail and its caching through the thumbnail template tag. I thought maybe I could use it in a raw way but the tag requires a geometry argument.
Is there an existing Django package I could use to cache images? Should I write a template tag similar to sorl-thumbnail's thumbnail tag to enable image caching by using Django's built-in cache?
This is not a job for redis and isn't a good use case for django. If you want to cache images in memory to serve from the server, front your django app server (like uwsgi or gunicorn) and nginx and use varnish to cache the images in memory. Redis does not do great for storing/retrieving large blobs.

How to change django FileFiled 'storage' AFTER uploading?

I am developing two web sites using the Django framework.
The thing is - one site is sharing part of the content from the other one.
They both use different amazon WS buckets to store images, etc.
So for the site which shares some content with another one I need to specify a different MEDIA_URL, but it seems impossible cause 'upload_to' and 'storage' parameters of the FileField only influence the file being uploaded.
Is there any way to use another storage when displaying image after it was uploaded?

Using Django's admin interface to upload large file to GAE

I've been trying to find a way to upload a large file to GAE's datastore using Django's admin interface, but haven't found an answer that specifically addresses this issue. I'm fairly new to Python/Django, so there might be an angle that I'm not looking at.
I've been looking at the django-filetransfers solution, but I'm not sure how to integrate that into the admin interface. Any suggestions would be great!
File uploads to the appengine are handled using the blobstore and not the datastore.
https://developers.google.com/appengine/docs/python/blobstore/overview#Complete_Sample_App
The datastore filesize limit is 1 megabyte. So, attempting to upload a large file into the appengine's non-relational database isn't going to work. This is by design.
The documentation I provided above shows you how to implement large file uploads.

django store image in database

Does anyone know if there's an out-of-the box way of storing images directly in the database vs. using ImageField model type that simply uploads it to the MEDIA_ROOT.
And if there is, how does one serve those images then?
Cheers
No, there isn't. And for good reason. It's horribly inefficient to store and serve images from the database. Store them on the filesystem, and serve them directly from Apache.
There is a nice solution here: http://djangosnippets.org/snippets/1305/ it stores content in a database blob.
It seems there is no built-in BlobField in Django. However, there is one available here. I'm not sure if it supports all backends, but it might work for you. With that, you could write up a form & view that uploades the image as an attachment and stores it as a blob in the database.