django boto3: NoCredentialsError -- Unable to locate credentials -


i trying use boto3 in django project upload files amazon s3. credentials defined in settings.py:

aws_access_key = xxxxxxxx aws_secret_key = xxxxxxxx s3_bucket = xxxxxxx 

in views.py:

import boto3  s3 = boto3.client('s3') path = os.path.dirname(os.path.realpath(__file__)) s3.upload_file(path+'/myphoto.png', s3_bucket, 'myphoto.png') 

the system complains unable locate credentials. have 2 questions:

(a) seems supposed create credential file ~/.aws/credentials. in django project, have put it?

(b) s3 method upload_file takes file path/name first argument. possible provide file stream obtained form input element <input type="file" name="filetoupload">?

this use direct upload, hope provides assistance.

import boto boto.exception import s3createerror boto.s3.connection import s3connection  conn = s3connection(settings.aws_access_key,                     settings.aws_secret_key,                     is_secure=true) try:     bucket = conn.create_bucket(settings.s3_bucket) except s3createerror e:     bucket = conn.get_bucket(settings.s3_bucket)  k = boto.s3.key.key(bucket) k.key = filename k.set_contents_from_filename(filepath) 

not sure (a) django flexible file management.

regarding (b) can sign upload , directly client reduce bandwidth usage, quite sneaky , secure too. need use javascript manage upload. if want details can include them here.


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -