AWSinAction / code

Code of Amazon Web Services in Action, 1st edition
https://www.manning.com/books/amazon-web-services-in-action
MIT License
269 stars 162 forks source link

chapter 7 gallery #3

Closed ghost closed 7 years ago

ghost commented 8 years ago

Not sure if it's my config or something else. It strips off file extension upon upload. Then image is blank on the page

andreaswittig commented 8 years ago

Thanks for your feedback. I guess the problem is the missing content type. What browser are you using and what image file type?

ghost commented 8 years ago

Chrome. Image is jpeg. Where do i specify content type? as attribute?

andreaswittig commented 8 years ago

Unfortunately I'm not able to re-produce your issue. It is true, that the gallery app is ignoring the file extension. But I don't think this is a big issue.

It's possible that your browser doesn't show the image correctly because of a missing/wrong Content-Type when loading the image from S3.

Could you please try to change the following part in chapter7/gallery/server.js and upload a new photo afterwards?

Old

var params = {
    Body: image,
    Bucket: bucket,
    Key: uuid.v4(),
    ACL: "public-read",
    ContentLength: image.byteCount
};

New

var params = {
    Body: image,
    Bucket: bucket,
    Key: uuid.v4(),
    ACL: "public-read",
    ContentLength: image.byteCount,
    ContentType: image.headers["content-type"]
};