Skip to content

Commit

Permalink
Allow all file types
Browse files Browse the repository at this point in the history
  • Loading branch information
PatelUtkarsh committed Apr 25, 2021
1 parent da3d5d2 commit f03ee1f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions upload-s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,33 @@
import imghdr
import random
import string
import mimetypes
from subprocess import call
from os.path import expanduser, exists, basename, getsize
from workflow import Workflow

def capture():
randomBit = ''.join(random.SystemRandom().choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in range(5))
file_name = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S'+randomBit+'.png')
random_bit = ''.join(random.SystemRandom().choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in range(5))
file_name = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S'+random_bit+'.png')
content_type = 'image/png'
if (sys.argv[1] != ""):
file_path = sys.argv[1]
content_type = mimetypes.MimeTypes().guess_type(file_path)[0]
_head, file_name = os.path.split(file_path)
file_names = file_name.split('.')
file_names.insert(1,'-' + random_bit + '.')
file_name = "".join(file_names)
else:
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:
sys.exit()
return file_path, file_name
return file_path, file_name, content_type

def main(wf):
import boto3
file_path, file_name = capture()
file_path, file_name, content_type = capture()
bucket_name = os.getenv('bucket_name')
region_name = os.getenv('region_name')
namespace = os.getenv('namespace')
Expand All @@ -38,7 +45,7 @@ def main(wf):
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"})
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)
print (output,end='')

Expand Down

0 comments on commit f03ee1f

Please sign in to comment.