我有這個奇怪的問題與AWS S3工作時。我正在研究可以將圖像存儲到AWS存儲桶的應用程序。使用Multer作爲中間件和S3FS庫來連接並上傳到AWS。MalformedXML:您提供的XML沒有得到很好的形成或沒有驗證對我們發佈的架構
但下面的錯誤彈出,當我嘗試上傳的內容。
「MalformedXML:您提供的XML沒有得到很好的形成或沒有驗證對我們敬上 HED模式」
Index.js
var express = require('express');
var router = express();
var multer = require('multer');
var fs = require('fs');
var S3FS = require('s3fs');
var upload = multer({
dest: 'uploads'
})
var S3fsImpl = new S3FS('bucket-name', {
region: 'us-east-1',
accessKeyId: 'XXXXXXXXXXXX',
secretAccessKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
});
/* GET home page. */
router.get('/', function (req, res, next) {
res.render('profile', {
title: 'Express'
});
});
router.post('/testupload', upload.single('file'), function (req, res) {
var file = req.file;
console.log(file);
var path = req.file.path;
var stream = fs.createReadStream(path);
console.log(stream);
S3fsImpl.writeFile(file.name, stream).then(function() {
fs.unlink(file.path, function (err) {
if (err) {
console.log(err);
}
});
res.redirect('/profile');
})
});
module.exports = router;
編輯 輸出:
{ fieldname: 'file',
originalname: '441_1.docx',
encoding: '7bit',
mimetype: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
destination: 'uploads',
filename: '662dcbe544804e4f50dfef1f52b40d22',
path: 'uploads\\662dcbe544804e4f50dfef1f52b40d22',
size: 13938 }
ReadStream {
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 65536,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: null,
pipesCount: 0,
flowing: null,
ended: false,
endEmitted: false,
reading: false,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events: { end: [Function] },
_eventsCount: 1,
_maxListeners: undefined,
path: 'uploads\\662dcbe544804e4f50dfef1f52b40d22',
fd: null,
flags: 'r',
mode: 438,
start: undefined,
end: undefined,
autoClose: true,
pos: undefined,
bytesRead: 0 }
的package.json
{
"name": "aws-s3-images",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.17.1",
"connect-multiparty": "^2.0.0",
"cookie-parser": "~1.4.3",
"debug": "~2.6.3",
"express": "~4.15.2",
"hbs": "~4.0.1",
"morgan": "~1.8.1",
"multer": "^1.3.0",
"s3fs": "^2.5.0",
"serve-favicon": "~2.4.2"
},
"description": "AWS S3 uploading images",
"main": "app.js",
"devDependencies": {},
"keywords": [
"javascript"
],
"author": "reeversedev",
"license": "MIT"
}
你可以包括你在提問上傳XML? – guest271314
你能告訴我在哪裏可以找到它嗎? @ guest271314 –
問題不在於您的XML,而在於正確設置您的AWS對象。你有沒有正確輸入你的水桶名稱和其他參數? –