Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mesoscope/cellpack into fea…
Browse files Browse the repository at this point in the history
…ture/upload-to-s3
  • Loading branch information
rugeli committed Oct 3, 2023
2 parents f6533c9 + fee423f commit 14042b5
Show file tree
Hide file tree
Showing 60 changed files with 84,621 additions and 644 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/analyze.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Analyze

on: push
on:
push:
branches:
- main
pull_request:

jobs:
Analyze:
Expand Down
15 changes: 11 additions & 4 deletions cellpack/autopack/AWSHandler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import logging
from pathlib import Path

import boto3
from botocore.exceptions import ClientError
from pathlib import Path


class AWSHandler(object):
Expand Down Expand Up @@ -33,14 +34,13 @@ def get_aws_object_key(self, object_name):

def upload_file(self, file_path):
"""Upload a file to an S3 bucket
:param file_path: File to upload
:param bucket: Bucket to upload to
:param object_name: S3 object name. If not specified then file_path is used
:return: True if file was uploaded, else False
"""

file_name = Path(file_path).stem
file_name = Path(file_path).name

object_name = self.get_aws_object_key(file_name)
# Upload the file
Expand All @@ -57,7 +57,6 @@ def upload_file(self, file_path):

def create_presigned_url(self, object_name, expiration=3600):
"""Generate a presigned URL to share an S3 object
:param object_name: string
:param expiration: Time in seconds for the presigned URL to remain valid
:return: Presigned URL as string. If error, returns None.
Expand All @@ -76,3 +75,11 @@ def create_presigned_url(self, object_name, expiration=3600):
# The response contains the presigned URL
# https://{self.bucket_name}.s3.{region}.amazonaws.com/{object_key}
return url

def save_file(self, file_path):
"""
Uploads a file to S3 and returns the presigned url
"""
file_name = self.upload_file(file_path)
if file_name:
return self.create_presigned_url(file_name)
Loading

0 comments on commit 14042b5

Please sign in to comment.