Tuesday, 15 April 2014

python - Using Amazon S3 on django to upload Images with ImageField -



python - Using Amazon S3 on django to upload Images with ImageField -

i installed django-storages pip (pip install django-storages)

got settings aws preferences:

default_file_storage = 'storages.backends.s3.s3storage' aws_storage_bucket_name = 'bar.media' aws_access_key_id = 'myawesomekeyid' aws_secret_access_key = 'blahblahblah'

i got model this:

def bar(model): image = models.imagefield(upload_to='bar')

on forms.py:

class barform(forms.form): image = forms.filefield(label='logo',required=false) def __init__(self, *args, **kwargs): super(barform, self).__init__(*args,**kwargs) self.fields['image'].label='my awesome photo'

on views.py:

@csrf_exempt def bar_web(request): context = {} if request.method == 'post': form = barform(request.post, request.files) context['form'] = form if form.is_valid(): try: logofile = request.files['image'] print 'pic: '+str(logofile) except: logofile = false if logofile: bar = bar(image=logofile) bar.save() bar.reload()

on template:

<p>image name: {{bar.image.name}}</p> <p>image url: {{bar.image.url}}</p> <p>image : {{bar.image.content_type}}</p> <p>image path: {{bar.image.path}}</p>

but nil printed.

i see file name on prints; nil happen s3. there no file uploaded.

what's error didn't see?

my problem wrong configuration of iam; these video may help other users...

https://www.youtube.com/watch?v=juffwmbejkw

python django amazon-web-services amazon-s3 django-models

No comments:

Post a Comment