multer

How to upload image using javascript fetch api and express multer

亡梦爱人 提交于 2019-12-07 06:47:31
问题 I am working in a reactjs application where i have to upload user image. I am getting file on onChange event of file input and passing it parent component and parent component will make a post request using the data Server side I am using express and multer for file upload and client side using fetch api to upload the image. Thanks in advance :) 回答1: I figure it out To upload an file/image to multer we need a form enctype="multipart/form-data" without that it wont work with multer I am

Multer, Node, EACCES error on C9.io

自古美人都是妖i 提交于 2019-12-06 21:44:33
Hiya all thanks in advance for any help you can provide. I am using C9.io, node, express, multer, gridfs-stream. And Im getting: /home/ubuntu/workspace/node_modules/multer/index.js:25 mkdirp(dest, function(err) { if (err) throw err; }); Error: EACCES, mkdir '/uploads' I run the server.js script and that is the error that I get. I believe is something to do with permissions but i have tried chown the public folder and chmod ax, you guys have any other suggestions as to what to do?. Still get same error. The code I have is server.js app.use('/uploads', express.static(__dirname + '/public/uploads

Multer create new folder with data

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 16:40:22
问题 I use multer. Question 1 When I put the following snippet in the app.js app.use(multer({ dest: './uploads' } ).single('file')); it creates a new folder under the root folder, my question is about this new folder's lifeCycle, When it'll be deleted? How much the size of the folder could be after 100 call? Question 2 If I don't want to limit the file size, what I should put in the configuration? app.use(multer({ dest: './public/profile/img/', limits: { fieldNameSize: 50, files: 1, fields: 5,

Multer | Stop file upload

回眸只為那壹抹淺笑 提交于 2019-12-06 09:49:22
问题 I am using expressjs 4.0 along with multer to handle file uploads. Problem is, I want to stop file upload when the file's size exceeds a maxSize variable. But multer uploads file anyways. Is there a way to stop this behaviour. Some example code : app.post('/upload', function(req, res) { var maxSize = 32 * 1000 * 1000 // 32mb max if(req.files.file.length > maxSize) { // stop upload } else { // continue res.send(201); } }); 回答1: According to Multer documentation: (https://www.npmjs.org/package

Node.js: Multer upload with promise?

戏子无情 提交于 2019-12-06 04:24:52
问题 I have this express route with multer file-upload. When the upload is complete, I would like to encode the image to base64 and send with response. However when I do it like this, the code tries to execute the base64 encoding before the file is created to the folder. Edit : Added storage & upload functions const storage = multer.diskStorage({ destination: (req, file, callback) => { if (!fs.existsSync('./uploads')) { fs.mkdirSync('./uploads'); } let path = './uploads'; callback(null, path); },

Express file upload with multer and gridfs (corrupted file ?)

故事扮演 提交于 2019-12-06 04:10:09
I'm trying to upload a file (an image), the upload is fine, the file is stored in Mongo and have the same content type and same size as the original file, then when I try to download it, the file is corrupted but keeps the same content type (if I upload a pdf, it is recognized as a pdf, if it is a png, it is also recognized, but I can't open them). I don't understand what is wrong with this, it is pretty simple and standard. For the upload from the client, I use angular ng-upload, for the download, it is a simple GET request to the route defined in the code. EDIT : The file is well uploaded on

Get image sent from post in node.js

三世轮回 提交于 2019-12-06 03:50:13
I need to use python to send an image through post and then download it on the node.js server side. Python code: import requests from PIL import Image import json url = 'http://127.0.0.1:8080/ay' files = {'file': open('image.jpg', 'rb')} r = requests.post(url, data = files) Node.js code: var app = express(); app.use(bodyparser.json({ limit: '50mb' })); app.use(bodyparser.urlencoded({ limit: '50mb', extended: true })); app.post('/ay', function(req, res) { var base64Data = req.body.file require("fs").writeFile("out.png", base64Data, 'base64', function(err) { console.log(err); }); res.send('done'

Should not allow file upload if anyone changes extension from exe to png via multer in node js application

隐身守侯 提交于 2019-12-06 02:35:31
I'm uploading file using multer in my nodejs (express js) application which is working fine. I have put a mime type check there also to allow only png files but if I change the ext of the uploaded file from abc.exe to abc.png it also gets uploaded which is wrong. here is my code. var multer = require('multer'); var imagefolder = __base + 'public/complaintimages/'; var diskstorage = multer.diskStorage({ destination: function (req, file, cb) { if (common.ImageMimeTypes.indexOf(file.mimetype) < 0) { common.ActionOutput.Status = common.ActionStatus.WrongFileUploaded; common.ActionOutput.Message =

How to post multipart/form-data from Angular to Nodejs Multer?

我是研究僧i 提交于 2019-12-05 04:44:10
From Angular I want to upload a image as Blob data to nodeJS server. The server uses multer in the backend. The image file is generated by canvas render. I am getting the following error from the server: Error: Multipart: Boundary not found status:500 The following is my code. Please help me to find out the issue. Angular: // blob:Blob; -> it has valid image data. var formData: FormData = new FormData(); formData.append('banner', blob, "my-file.png") this.http.post(url, formData, { headers: new Headers({ 'Content-Type': 'multipart/form-data' }) }) .toPromise() .then(res => { console.log(res);

how to properly configure meteor to work with node file uploading module 'multer'

有些话、适合烂在心里 提交于 2019-12-05 02:35:12
I'm just starting with meteor. I've found, and added the 'multer' package: meteor add pfafman:multer Now, I wonder how to configure the server side of meteor to use. In my plain node app, I use it like this: app.use(multer({ dest: './uploads/', rename: function (fieldname, filename) { return filename+Date.now(); }, onFileUploadStart: function (file) { console.log(file.originalname + ' is starting ...'); }, onFileUploadComplete: function (file) { console.log(file.fieldname + ' uploaded to ' + file.path); var fileName = file.name; var done=true; } })); What is the equivalent server code for this