[Fixed]-How to mix Django, Uploadify, and S3Boto Storage Backend?

1πŸ‘

Use a URLField.

πŸ‘€John Mee

1πŸ‘

I had a similar issue where i want to store file to s3 either directly using FileField or i have an option for the user to input the url directly. So to circumvent that, i used 2 fields in my model, one for FileField and one for URLField. And in the template i could use β€˜or’ to see which one exists and to use that like {{ instance.filefield or instance.url }}.

πŸ‘€tejinderss

1πŸ‘

This is untested, but you should be able to use:

from django.core.files.storage import default_storage
f = default_storage.open('name_you_expect_in_s3', 'r')
#f is an instance of S3BotoStorageFile, and can be assigned to a field
obj, created = YourObject.objects.get_or_create(**stuff_you_know)
obj.s3file_field = f
obj.save()

I think this should set up the local pointer to s3 and save it, without over writing the content.

ETA: You should do this only after the upload completes on S3 and you know the key in s3.

0πŸ‘

Checkout django-filetransfers. Looks like it plays nice with django-storages.

πŸ‘€michael

-1πŸ‘

I’ve never used django, so ymmv πŸ™‚ but why not just write a single byte to populate the content? That way, you can still use FieldFile.

πŸ‘€Joel Martinez

-1πŸ‘

I’m thinking that writing actual SQL may be the easiest solution here. Alternatively you could subclass S3BotoStorage, override the _save method and allow for an optional kwarg of filepath which sidesteps all the other saving stuff and just returns the cleaned_name.

πŸ‘€Bob Spryn

Leave a comment