Fix CORS s3 upload.
This commit is contained in:
parent
c276bce177
commit
b1a5b9c343
3 changed files with 20 additions and 20 deletions
|
@ -29,17 +29,13 @@ class UserRequestFiles(object):
|
|||
self._secret_key = s3_secret_key
|
||||
self._prefix = 'userfiles'
|
||||
|
||||
def prepare_for_drop(self, mimeType):
|
||||
def prepare_for_drop(self, mime_type):
|
||||
""" Returns a signed URL to upload a file to our bucket. """
|
||||
file_id = str(self._prefix + '/' + str(uuid4()))
|
||||
|
||||
expires = str(int(time.time() + 300))
|
||||
signingString = "PUT\n\n" + mimeType + "\n" + expires + "\n/" + self._bucket_name + "/" + file_id;
|
||||
|
||||
hmac_signer = hmac.new(self._secret_key, signingString, sha)
|
||||
signature = base64.b64encode(hmac_signer.digest())
|
||||
|
||||
url = "http://s3.amazonaws.com/" + self._bucket_name + "/" + file_id + "?AWSAccessKeyId=" + self._access_key + "&Expires=" + expires + "&Signature=" + urllib.quote(signature);
|
||||
logger.debug('Requested upload url with content type: %s' % mime_type)
|
||||
file_id = str(uuid4())
|
||||
full_key = os.path.join(self._prefix, file_id)
|
||||
k = Key(self._bucket, full_key)
|
||||
url = k.generate_url(300, 'PUT', headers={'Content-Type': mime_type})
|
||||
return (url, file_id)
|
||||
|
||||
def store_file(self, flask_file):
|
||||
|
|
Reference in a new issue