chibisov / django-proxy-storage

Provides simple Django storage that proxies every operation to original storage and saves meta information about files to database
http://chibisov.github.io/django-proxy-storage/docs
40 stars 11 forks source link

Bug in open(path) if upload_dir don`t set #7

Open pahaz opened 8 years ago

pahaz commented 8 years ago

Example:

class TestFile(models.Model):
    name = models.CharField(max_length=255, default=get_random_string)
    file = ProxyStorageFileField(storage=storage)

We have ProxyStorageFileField without upload_to. In this case we can`t find uploaded file =/

I use this test function for serving files:

def serve_from_storage(request, path):
    try:
        file = storage.open(utils.clean_path(path))
    except Exception:
        raise Http404()
    else:
        return HttpResponse(file, content_type=guess_type(path)[0])

urlpatterns = patterns(
    '',
    url(r'^media/(?P<path>.+)', serve_from_storage),
)