Skip to content

Commit

Permalink
Add support for shorturl
Browse files Browse the repository at this point in the history
  • Loading branch information
PatelUtkarsh committed Jun 22, 2022
1 parent be1f2e1 commit b5a080a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Config Environment Variables:
- bucket_name: Oracle bucket name. e.g. `my-bucket-name`
- namespace: Oracle namespace.
- tinypng_api_key: Get your tinypng api key from https://tinypng.com/developers to compress images before uploading.
- short_url: You can add proxy to cloudflare or aws lambda to make url short. Example: https://gist.github.com/PatelUtkarsh/0438735990e0b6f373b4deaf7f9be277

**Note** 🗒️: if tinypng_api_key is set, it will compress original image and replace it before uploading to object storage.

Expand All @@ -40,6 +41,8 @@ TinyPng will compress png, webp and jpg images.
upload TYPE-FILENAME-HERE
```

### Issue with python 2?
Read setup guide at https://www.alfredapp.com/help/kb/python-2-monterey/

## Forked source: 🙌
- https://github.com/tonyxu-io/Alfred-Workflow-Upload-S3
9 changes: 8 additions & 1 deletion upload-s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ def main(wf):
endpoint_url="https://%s.compat.objectstorage.%s.oraclecloud.com" %(namespace, region_name)
)
s3.upload_file(file_path, bucket_name, file_name, ExtraArgs={'ContentType': content_type})
output = "https://objectstorage.%s.oraclecloud.com/n/%s/b/%s/o/%s" %(region_name,namespace,bucket_name,file_name)
shorturl = os.getenv('shorturl')
# if short url is not empty and exists.
if shorturl:
if shorturl[len(shorturl)-1] != "/":
shorturl = shorturl + "/"
output = "%s%s" %(shorturl,file_name)
else:
output = "https://objectstorage.%s.oraclecloud.com/n/%s/b/%s/o/%s" %(region_name,namespace,bucket_name,file_name)
print (output,end='')

if __name__ == '__main__':
Expand Down

0 comments on commit b5a080a

Please sign in to comment.