Files
notifications-admin/app/s3_client/s3_letter_upload_client.py
Katie Smith 7368245c9a Show letter preview once file is uploaded
This shows the sanitised letter preview if the file had no validation
errors or the preview with the overlay if it failed validation.
2019-09-12 09:54:36 +01:00

28 lines
812 B
Python

from boto3 import resource
from flask import current_app
from notifications_utils.s3 import s3upload as utils_s3upload
def get_transient_letter_file_location(service_id, upload_id):
return 'service-{}/{}.pdf'.format(service_id, upload_id)
def upload_letter_to_s3(data, file_location, status):
utils_s3upload(
filedata=data,
region=current_app.config['AWS_REGION'],
bucket_name=current_app.config['TRANSIENT_UPLOADED_LETTERS'],
file_location=file_location,
metadata={'status': status}
)
def get_letter_pdf_and_metadata(file_location):
s3 = resource('s3')
s3_object = s3.Object(current_app.config['TRANSIENT_UPLOADED_LETTERS'], file_location).get()
pdf = s3_object['Body'].read()
metadata = s3_object['Metadata']
return pdf, metadata