Skip to content

Commit

Permalink
Patch for oracle object-storage 🚀 v1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
PatelUtkarsh committed Jul 11, 2020
1 parent 7f7a620 commit b1eb3a4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# Alfred Workflow: Upload Image to AWS S3
# Alfred Workflow: Upload Screenshot to Oracle Cloud Object storage using s3 compatible API.

This workflow helps you upload image in your clipboard or local disk to S3 and put the public url of the image to your clipboard.
This workflow is especially helpful if you are a markdown fan and you can easily get public url and use it in markdown document.
This workflow helps you upload screenshot in your clipboard or local disk to S3 and put the public url of the image to your clipboard.

## Overview

This workflow is written in Python. And used Boto3 as AWS client to upload image.

## Download

https://github.com/tonyxu-io/Alfred-Workflow-Upload-S3/releases
https://github.com/PatelUtkarsh/Alfred-Workflow-Upload-S3/releases

## Usage

Check https://www.ateam-oracle.com/aws-s3-to-oci-access-best-practices on how to get environment variables.

Config Environment Variables:

- access_key: S3 access key
- secret_key: S3 access secret
- bucket_name: S3 bucket name. e.g. `my-bucket-name`
- bucket_uri: S3 bucket uri without trailing slash. e.g. `https://s3-us-west-1.amazonaws.com/my-bucket-name`
- access_key: Oracle access key
- secret_key: Oracle access secret
- region_name: Oracle cloud region name
- bucket_name: Oracle bucket name. e.g. `my-bucket-name`
- namespace: Oracle namespace.

Upload image from clipboard:

Expand All @@ -32,8 +34,5 @@ Upload image from local:
upload TYPE-FILENAME-HERE
```

## Tutorials

Check out my blog to see how I made this workflow:

https://tonyxu.io/posts/create-alfred-workflow-for-uploading-screenshot-to-s3/
## Forked source: 🙌
- https://github.com/tonyxu-io/Alfred-Workflow-Upload-S3
Binary file removed Upload Image to S3.alfredworkflow
Binary file not shown.
14 changes: 7 additions & 7 deletions upload-s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@
def capture():
file_name = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S.png')
if (sys.argv[1] != ""):
# Image path is expected if additional argument found and will be verified by Alfred file filter
file_path = sys.argv[1]
else:
# Get image from clipboard
file_path = os.path.join('/tmp', file_name)
atexit.register(lambda x: os.remove(x) if os.path.exists(x) else None, file_path)
save = call(['./pngpaste', file_path])
if save == 1:
# Image not found in clipboard
print ("No image found in clipboard")
sys.exit()
return file_path, file_name

def main(wf):
import boto3
file_path, file_name = capture()
bucket_name = os.getenv('bucket_name')
region_name = os.getenv('region_name')
namespace = os.getenv('namespace')
s3 = boto3.client(
's3',
service_name='s3',
aws_access_key_id=os.getenv('access_key'),
aws_secret_access_key=os.getenv('secret_key')
aws_secret_access_key=os.getenv('secret_key'),
region_name=region_name,
endpoint_url="https://%s.compat.objectstorage.%s.oraclecloud.com" %(namespace, region_name)
)
s3.upload_file(file_path, bucket_name, file_name, ExtraArgs={'ContentType': "image/png"})
output = "%s/%s" %(os.getenv('bucket_uri'), file_name)
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 b1eb3a4

Please sign in to comment.