Store all data about uploaded letters in the S3 metadata

We had been storing whether or not a file was valid in the S3 metadata,
but using the query string of the URL to store the original filename
and the page count. This meant that if you tried to view the preview
letter page without the query string you would see a `500`. It was
possible for this to happen if you were signed out of Notify while on
the preview page - you would be redirected back to the preview page but
without the query string, causing an error.
This commit is contained in:
Katie Smith
2019-10-07 15:22:11 +01:00
parent 28c901d5b9
commit 11543e15be
5 changed files with 71 additions and 28 deletions

View File

@@ -7,17 +7,22 @@ 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):
def upload_letter_to_s3(data, *, file_location, status, page_count, filename):
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}
metadata={
'status': status,
'page_count': str(page_count),
'filename': filename,
}
)
def get_letter_pdf_and_metadata(file_location):
def get_letter_pdf_and_metadata(service_id, file_id):
file_location = get_transient_letter_file_location(service_id, file_id)
s3 = resource('s3')
s3_object = s3.Object(current_app.config['TRANSIENT_UPLOADED_LETTERS'], file_location).get()
@@ -25,3 +30,11 @@ def get_letter_pdf_and_metadata(file_location):
metadata = s3_object['Metadata']
return pdf, metadata
def get_letter_metadata(service_id, file_id):
file_location = get_transient_letter_file_location(service_id, file_id)
s3 = resource('s3')
s3_object = s3.Object(current_app.config['TRANSIENT_UPLOADED_LETTERS'], file_location).get()
return s3_object['Metadata']