-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Returning Content-Type header - based on the S3 file Content-Type pro… #1
Conversation
const bufferImage = await modifiedImage.toBuffer(); | ||
return { | ||
body: bufferImage.toString('base64'), | ||
contentType: request.originalImageContentType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Splitting the response - we now return both body and contentType from the request.
@@ -46,9 +48,9 @@ class ImageRequest { | |||
const request = s3.getObject(imageLocation).promise(); | |||
try { | |||
const originalImage = await request; | |||
return Promise.resolve(originalImage.Body); | |||
return Promise.resolve({ body: originalImage.Body, contentType: originalImage.ContentType }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s3.getObject
returns the ContentType (note the uppercase convention), we want to return in, with the body
@@ -26,7 +26,9 @@ class ImageRequest { | |||
this.bucket = this.parseImageBucket(event, this.requestType); | |||
this.key = this.parseImageKey(event, this.requestType); | |||
this.edits = this.parseImageEdits(event, this.requestType); | |||
this.originalImage = await this.getOriginalImage(this.bucket, this.key) | |||
const originalImageWithContentType = await this.getOriginalImage(this.bucket, this.key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to have a new property on the request - originalImageContentType
const response = { | ||
"statusCode": 200, | ||
"headers" : getResponseHeaders(), | ||
"body": processedRequest, | ||
"headers": getResponseHeaders(false, contentType), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now use false to indicate there is no error, we use the contentType we got from the imageHandler
@@ -20,20 +20,19 @@ exports.handler = async (event) => { | |||
const imageHandler = new ImageHandler(); | |||
try { | |||
const request = await imageRequest.setup(event); | |||
console.log(request); | |||
const processedRequest = await imageHandler.process(request); | |||
const { contentType, body } = await imageHandler.process(request); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get relevant data from handler
const corsEnabled = (process.env.CORS_ENABLED === "Yes"); | ||
const headers = { | ||
"Access-Control-Allow-Methods": "GET", | ||
"Access-Control-Allow-Headers": "Content-Type, Authorization", | ||
"Access-Control-Allow-Credentials": true, | ||
"Content-Type": "image" | ||
"Content-Type": contentType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning S3 content type
hi @ofir-shapira-como , sorry for overlooking this, just noticed this just. They have fixed the official project, so it best to use that one instead :) i am merging this anyway, we are still running this fork and your changes will benefit us. |
First, thanks for the fork.
This PR solves this issue aws-solutions#103, we want to have the correct Content-Type header returned to clients.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.