我的節點js代碼從我的服務器tmp.png打開一個本地png文件,然後嘗試將其保存到亞馬遜S3。我一直遇到問題,我懷疑它與編碼有關。它唯一的工作方式是使用base64編碼(我不想爲我的照片編碼)。Cant的保存圖像與awssum和nodejs到亞馬遜S3
fs = require('fs');
var awssum = require('awssum');
var amazon = awssum.load('amazon/amazon');
var s3Service = awssum.load('amazon/s3');
var s3 = new s3Service('mykey', 'mysecret', 'account', amazon.US_WEST_1);
fs.readFile('./tmp.png', function (err, data){
if(err){
console.log("There was an error opening the file");
} else {
s3.PutObject({
BucketName : 'my-bucket',
ObjectName : 'tmp.png',
ContentType : 'image/png',
ContentLength : data.length,
Body : data,
}, function(err, data) {
if(err){
console.log("There was an error writing the data to S3:");
console.log(err);
} else {
console.log("Your data has been written to S3:");
console.log(data);
}
});
}
});
顯然我的水桶實際上是我獨特的水桶名稱。我從亞馬遜返回的消息是請求超時:
您的與服務器的套接字連接在超時期限內未讀取或寫入。空閒連接將被關閉。
注意,這個代碼是從約V0.4使用AwsSum(我的圖書館)的舊版本。新版本v0.5及更高版本的語法略有不同,因此值得關注AwsSum附帶的示例/文件夾。 – chilts 2012-07-25 03:33:58