Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 需要使用fastify multer getting[函数:MulterHandler]将图像上载到AWS S3服务器错误 使用的软件包_Node.js_Amazon S3_File Upload_Fastify - Fatal编程技术网

Node.js 需要使用fastify multer getting[函数:MulterHandler]将图像上载到AWS S3服务器错误 使用的软件包

Node.js 需要使用fastify multer getting[函数:MulterHandler]将图像上载到AWS S3服务器错误 使用的软件包,node.js,amazon-s3,file-upload,fastify,Node.js,Amazon S3,File Upload,Fastify,2.将文件上载到AWS S3 bucket的函数 uploadInvoice = async (req, res) => { var files = upload.single("file"); try { const s3FileURL = ' https://up.s3.amazonaws.com/'; let


2.将文件上载到AWS S3 bucket的函数

   uploadInvoice = async (req, res) => {
             var files = upload.single("file");
             try {
             
             const s3FileURL = ' https://up.s3.amazonaws.com/';
         
             let s3bucket = new AWS.S3({
                 secretAccessKey: "",
                 accessKeyId: "",
                 region: ""
             });
         
             const params = {
                 Bucket: '',
                 Body: files.buffer,
                 ContentType: files.mimetype,
                 ACL: "public-read",
                 key: files.originalname
             };
            
             s3bucket.upload(params, function (err, files) {
                 if (err) {
                     res.status(500).json({ error: true, Message: err });
                 } else {
                     res.send({ files });
                     var newFileUploaded = {
                         description: req.body.description,
                         fileLink: s3FileURL + files.originalname,
                         s3_key: params.Key
                     };
                     var document = new DOCUMENT(newFileUploaded);
                     document.save(function (error, newFile) {
                         if (error) {
                             throw error;
                         }
                     });
                 }
             });
         };
我得到的错误是 HttpErrorResponse{headers:HttpHeaders,状态:500,状态文本:“内部服务器错误”,url:http://localhost:3000/v1/upload/files“,ok:false,…} 错误:{statusCode:500,错误:“内部服务器错误”,消息:“params.Body是必需的”} Header:HttpHeaders{normalizedNames:Map(0),lazyUpdate:null,lazyInit:ƒ} 消息:“的Http失败响应”http://localhost:3000/v1/upload/files: 500内部服务器错误“ 名称:“HttpErrorResponse” 好:错 现状:500 statusText:“内部服务器错误” url:“http://localhost:3000/v1/upload/files"
proto:在参数中的“键”是小写的,而在上传时,您使用的是params.Key,应该是params.Key,如果您使用Fastfy,请选择fs和pump,而不是multer,因为到目前为止Fastfy multer不能完全与AWS S3上传一起工作。

更新:multer在这种情况下不起作用,我使用fs和pump进行文件上传,它起作用了。
   uploadInvoice = async (req, res) => {
             var files = upload.single("file");
             try {
             
             const s3FileURL = ' https://up.s3.amazonaws.com/';
         
             let s3bucket = new AWS.S3({
                 secretAccessKey: "",
                 accessKeyId: "",
                 region: ""
             });
         
             const params = {
                 Bucket: '',
                 Body: files.buffer,
                 ContentType: files.mimetype,
                 ACL: "public-read",
                 key: files.originalname
             };
            
             s3bucket.upload(params, function (err, files) {
                 if (err) {
                     res.status(500).json({ error: true, Message: err });
                 } else {
                     res.send({ files });
                     var newFileUploaded = {
                         description: req.body.description,
                         fileLink: s3FileURL + files.originalname,
                         s3_key: params.Key
                     };
                     var document = new DOCUMENT(newFileUploaded);
                     document.save(function (error, newFile) {
                         if (error) {
                             throw error;
                         }
                     });
                 }
             });
         };