2017-06-06 64 views
0

使用AWS-SDK爲Javascript我遇到一個奇怪的問題,即特殊的字符不被把文本轉換爲對象AWS S3 putObject符號特殊chracters

這裏經過翻譯是我的代碼:

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 
}); 

這使得該顯示一個HTML頁面: 「版權©2017年

如何刪除加字符Â

+0

您是否嘗試將'ContentEncoding:'utf8''添加到'params'對象? – madebydavid

+1

utf8不是有效的內容編碼,@madebydavid。 'text/html的; charset = utf-8'然而,對於ContentType似乎是一個合適的值 –

+0

@ Michael-sqlbot完美的工作!非常感謝!!想把它作爲這個問題的答案嗎? – TonyDiaz

回答

1

取而代之的是...

ContentType: 'text/html' 

...明確告訴瀏覽器內容的字符編碼:

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

這同時設置內容type and subtype說S3將返回HTTP Content-Type響應頭,瀏覽器用它來正確解釋對象數據。