Get file dropping working and wire it up to call the build repo endpoint
This commit is contained in:
parent
fc6e3258a8
commit
28f6ff1605
4 changed files with 167 additions and 5 deletions
|
@ -4,6 +4,11 @@ import logging
|
|||
|
||||
from boto.s3.key import Key
|
||||
from uuid import uuid4
|
||||
import hmac
|
||||
import time
|
||||
import urllib
|
||||
import base64
|
||||
import sha
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -18,9 +23,25 @@ class UserRequestFiles(object):
|
|||
self._s3_conn = boto.s3.connection.S3Connection(s3_access_key,
|
||||
s3_secret_key,
|
||||
is_secure=False)
|
||||
self._bucket_name = bucket_name
|
||||
self._bucket = self._s3_conn.get_bucket(bucket_name)
|
||||
self._access_key = s3_access_key
|
||||
self._secret_key = s3_secret_key
|
||||
self._prefix = 'userfiles'
|
||||
|
||||
def prepare_for_drop(self, mimeType):
|
||||
""" 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);
|
||||
return (url, file_id)
|
||||
|
||||
def store_file(self, flask_file):
|
||||
file_id = str(uuid4())
|
||||
full_key = os.path.join(self._prefix, file_id)
|
||||
|
|
Reference in a new issue