123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- def upload_file_S3_handler(event, context):
- """ This method revolves around uploading a file to S3.
- Parameters
- event: Event generated from lambda
- """
- s3 = boto3.client("s3")
- file_name = event['headers']['file-name']
- user_id = event['headers']['user-id']
- file_content = event['body']
- bucket_name = cf.constants['bucket_name']
- file_id = str(uuid.uuid4())
- s3ServiceObj=S3Service()
- # Method call
- extension = s3ServiceObj.vald_file_checker(file_name)
- #print("The recieved value is",extension)
- if(extension == "invalid"):
- return {
- "statusCode": 400,
- "body": json.dumps(cf.response_message['fileFormat'])
- }
- try:
- response_upload_object = s3ServiceObj.upload_file_tos3(bucket_name,file_id,file_content)
- print(response_upload_object)
- if(response_upload_object['ResponseMetadata']['HTTPStatusCode']==200):
- response_upload_api_call_exec=upload_api_call_exec(file_id,file_name,user_id,extension)
- print("The response_upload-api_call_exec ",response_upload_api_call_exec)
- if(response_upload_api_call_exec!="failure"):
- return {
- "statusCode": 200,
- "body": response_upload_api_call_exec.content
- }
- else:
- return{
- "statusCode":200,
- "body":cf.response_message['file_upload_api_success']
- }
- else:
- return{
- "statusCode": 400,
- "body":cf.response_message['uploadException']
- }
- except:
- print("Issues while uploading file to s3")
- return {
- "statusCode": 400,
- "body": json.dumps(cf.response_message["uploadException"])
- }
|