def get(quest_id, file_name): """Return a signed request to upload the given file name to the given quest and the URL for the resource upon its upload. """ mime_type = flask.request.args['mime_type'] upload_path = 'quests/%s/%s' % (quest_id, file_name) return s3.s3_upload_signature(upload_path, mime_type)
def test_s3_upload_signature(self): """Test the s3_upload_signature function.""" signature = s3.s3_upload_signature("snake.png", "image/png") self.assertEqual( signature, { "file_name": "snake.png", "s3_url": "https://bucket.s3.amazonaws.com/snake.png", "cdn_url": "http://clouds.cloudfront.net/snake.png", "upload_args": { "url": "https://bucket.s3.amazonaws.com/", "method": "POST", "data": { "AWSAccessKeyId": "key", "success_action_status": "201", "acl": "public-read", "key": "snake.png", "Content-Type": "image/png", "Signature": "kETEObkncWe3ZPmvevjVxVNvojQ=", "Policy": "eyJjb25kaXRpb25zIjogW1siZXEiLCAiJGtleSIsICJz" "bmFrZS5wbmciXSwgeyJidWNrZXQiOiAiYnVja2V0In0s" "IHsiYWNsIjogInB1YmxpYy1yZWFkIn0sIFsiZXEiLCAi" "JENvbnRlbnQtVHlwZSIsICJpbWFnZS9wbmciXSwgeyJzd" "WNjZXNzX2FjdGlvbl9zdGF0dXMiOiAiMjAxIn1dLCAiZX" "hwaXJhdGlvbiI6ICIyMDEyLTEyLTIxVDAxOjAwOjAwLjA" "wMFoifQ==", }, }, }, )
def test_s3_upload_signature(self): """Test the s3_upload_signature function.""" signature = s3.s3_upload_signature('snake.png', 'image/png') self.assertEqual( signature, { 'file_name': 'snake.png', 's3_url': 'https://bucket.s3.amazonaws.com/snake.png', 'cdn_url': 'http://clouds.cloudfront.net/snake.png', 'upload_args': { 'url': 'https://bucket.s3.amazonaws.com/', 'method': 'POST', 'data': { 'AWSAccessKeyId': 'key', 'success_action_status': '201', 'acl': 'public-read', 'key': 'snake.png', 'Content-Type': 'image/png', 'Signature': 'kETEObkncWe3ZPmvevjVxVNvojQ=', 'Policy': "eyJjb25kaXRpb25zIjogW1siZXEiLCAiJGtleSIsICJz" "bmFrZS5wbmciXSwgeyJidWNrZXQiOiAiYnVja2V0In0s" "IHsiYWNsIjogInB1YmxpYy1yZWFkIn0sIFsiZXEiLCAi" "JENvbnRlbnQtVHlwZSIsICJpbWFnZS9wbmciXSwgeyJzd" "WNjZXNzX2FjdGlvbl9zdGF0dXMiOiAiMjAxIn1dLCAiZX" "hwaXJhdGlvbiI6ICIyMDEyLTEyLTIxVDAxOjAwOjAwLjA" "wMFoifQ==" } } })
def get(user_id, file_name): """Return a signed request to upload the given file name to as the given user's avatar. """ mime_type = flask.request.args['mime_type'] upload_path = 'avatars/%s/%s' % (user_id, file_name) return s3.s3_upload_signature(upload_path, mime_type)