multer

Post file from one server to another,using node.js , needle , busboy/multer

巧了我就是萌 提交于 2019-12-20 04:24:41
问题 I would like to move a small image from one server to another (both running node). As I search, I haven't found enough. This post remains unanswered. As I started experimenting I wrote the following to the first server : app.post("/move_img", function(req, res) { console.log("post handled"); fs.readFile(__dirname + "/img_to_move.jpg", function(err, data) { if (err) throw err; console.log(data); needle.post(server2 + "/post_img", { data: data, name : "test.jpg" }, function(result) { console

how to upload file saved in memory by multer to another API

雨燕双飞 提交于 2019-12-19 03:10:53
问题 I have 2 separate NodeJS APIs that uses multer to save a file in memory . My express middleware looks like this import multer from 'multer'; const storage = multer.memoryStorage(); export default multer({ storage }).single('image'); I am able to receive the file which is saved in memory successfully so my req.file.image looks like this { fieldname: 'image', originalname: 'image-2017-08-28-13-47-31-218.png', encoding: '7bit', mimetype: 'image/png', buffer: <Buffer 89 50 4e 47 0d 0a 1a 0 ... >,

how to upload file saved in memory by multer to another API

房东的猫 提交于 2019-12-19 03:09:22
问题 I have 2 separate NodeJS APIs that uses multer to save a file in memory . My express middleware looks like this import multer from 'multer'; const storage = multer.memoryStorage(); export default multer({ storage }).single('image'); I am able to receive the file which is saved in memory successfully so my req.file.image looks like this { fieldname: 'image', originalname: 'image-2017-08-28-13-47-31-218.png', encoding: '7bit', mimetype: 'image/png', buffer: <Buffer 89 50 4e 47 0d 0a 1a 0 ... >,

NodeJS Multer is not working

放肆的年华 提交于 2019-12-18 12:26:53
问题 I tried to file upload with NodeJS + ExpressJS + Multer but does not work well. My ExpressJS Version is 4.12.3 this is my source server.js: var express = require('express'), multer = require('multer'); var app = express(); app.use(express.static(__dirname + '/public')); app.use(multer({ dest: './uploads/'})); app.post('/', function(req, res){ console.log(req.body); // form fields console.log(req.files); // form files res.status(204).end() }); app.get('/', function(req, res) { res.sendFile(

Error handling when uploading file using multer with expressjs

你。 提交于 2019-12-18 05:15:35
问题 I am using multer to save the file on server developed through express & nodejs. I am usign following code. var express = require('express'), multer = require('multer') var app = express() app.get('/', function(req, res){ res.send('hello world'); }); app.post('/upload',[ multer({ dest: './uploads/'}), function(req, res){ res.status(204).end() }]); app.listen(3000); Multer saves the file for me in the specified destination folder. All this is working fine but I have following questions: If the

Image can not upload in right direction

天大地大妈咪最大 提交于 2019-12-13 22:22:35
问题 I am working on a image uploading website. User can take photo via their camera and upload. I am testing it with my iPhone 5S But the photo upload from iPhone display in the wrong direction on PC, and the right direction in mobile device. in my pc: the correct direction (the direction display in iPhone) in my upload process, I simply do nothing to the image, and I use Express and multer : var storage = multer.diskStorage({ destination: function(req, file, cb) { cb(null, 'public/uploads'); },

nodejs multer file upload, what happens file names are the same from 2 places

坚强是说给别人听的谎言 提交于 2019-12-13 08:58:04
问题 The concept is still not clear to me yet. For a very basic case, i can upload a file (say myFile.txt) using multer, and keep its original name in the server side. const upload = multer({ dest: `${UPLOAD_PATH}/` }); // multer configuration Now another person happen to upload a different file with same file name myFile.txt to the same folder in server side. Will it overwrite the previous one ? How do you normally manage this ? Thanks ! 回答1: Will it overwrite the previous one ? Yes it will

How to save an array of files to mongoDB database using multer?

梦想的初衷 提交于 2019-12-13 03:18:53
问题 I'm creating an endpoint using nodejs which will store an array of images using multer. It is allowing me to save a single image, but have no idea how to proceed for multiple images. For uploading single image this is the code I've written: router.post ('/upload',auth, upload.single('upload'), async (req:Request, res:Response) =>{ const bufferData = { image:req.file.buffer }; const image = new Image(bufferData); image.save(); res.send() },(error:Error, req:Request, res:Response, next

Multer - Stop File Uploading If Form Validation Fails

▼魔方 西西 提交于 2019-12-13 03:07:58
问题 i have mixed form with file upload and normal form fields, and while sending this form to Nodejs server i am validating form but problem is that i do not know how to stop uploading the file if (for example) one of the form field is empty. so for example: if(name.trim().length < 1){ //stop uploading of file return res.status(409).send({ message: 'provide name' }) } how can i do that (Multer & ExpressJS)? 回答1: I was using following code in my case (node & express). From routes.js file I am

New express-validator syntax : validate form processed by multer

北慕城南 提交于 2019-12-13 00:46:09
问题 So, I am building a small app in order to learn how to use express.js. I have a really simple form, submitting one text field and a file simultaneously. This is submitted through FormData, so I'm using multer on the back end to process the request. What I would like to do is perform a validation on the form's text input BEFORE taking any action concerning the file (i.e. save only if the validation succeeds, if not send some kind of error message). I used to do it that way <form id="form"