简体   繁体   中英

AWS S3 putObject symbols special chracters

Using the aws-sdk for Javascript I'm running into a odd issue where special charaters are not being translated after putting the text into an object

Here is my code:

var AWS = require('aws-sdk');

AWS.config.update({
 region: "us-east-1",
 endpoint: "s3.amazonaws.com"
});

var s3 = new AWS.S3();

var params = {
 Bucket: 'test-example',
 Key: 'test.html',
 Body: 'Copyright © 2017',
 ACL:'public-read',
 ContentType: 'text/html'
}
s3.putObject(params, function(err, data) {
 if (err) console.log(err, err.stack); // an error occurred
 else     console.log(data);           // successful response
});

Which renders to an HTML page that displays: " Copyright © 2017 "

How do I remove the addition character Â

Instead of this...

ContentType: 'text/html'

...explicitly tell the browser the character encoding of the content:

ContentType: 'text/html; charset=utf-8'

This sets both the content type and subtype that S3 will return in the HTTP Content-Type response header, which the browser uses to correctly interpret the object data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM