Last active
January 19, 2021 11:36
-
-
Save thanakijwanavit/092ed6c733b0c68d7f8ffd2b4aa88036 to your computer and use it in GitHub Desktop.
upload file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##### for signor | |
| from s3bz.s3bz import S3 | |
| def presign (bucket:str, key:str, expiry:int)->dict: | |
| return S3.presignUpload(bucket=bucket, key = key, expiry = 1000) | |
| ``` | |
| {'url': 'https://inventory-bucket-dev-manual.s3-accelerate.amazonaws.com/', | |
| 'fields': {'key': 'test', | |
| 'AWSAccessKeyId': 'AKIAVX4Z5TKDSNNNULGB', | |
| 'policy': 'eyJleHBpcmF0aW9uIjogIjIwMjEtMDEtMTlUMDU6MTc6NTFaIiwgImNvbmRpdGlvbnMiOiBbeyJidWNrZXQiOiAiaW52ZW50b3J5LWJ1Y2tldC1kZXYtbWFudWFsIn0sIHsia2V5IjogInRlc3QifV19', | |
| 'signature': 'rRYNuCNIEZG0eW8V1fdgnajcoMw='}} | |
| ``` | |
| ###### for client (uploader) | |
| from io import BytesIO | |
| def uploadFile(inputByte:bin, key='1000', presigned:dict): | |
| files = {'file': (key , BytesIO(inputByte))} | |
| r = requests.post(url = presigned['url'], data = presigned['fields'] , files = files) | |
| return r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment