multer

How to upload images to GCS bucket with multer and NodeJS?

余生长醉 提交于 2021-02-08 01:57:01
问题 I'm facing issues for uploading local images to my google cloud storage. I've already tried two methods. The first one is uploading with multer var storage = multer.diskStorage({ destination: (req, file, cb) => { cb(null, './uploads/') }, filename: (req, file, cb) => { cb(null, file.fieldname + '-' + Date.now()) } }); var upload = multer({storage: storage}).single('image'); app.post('/upload',function(req,res,next){ upload(req,res,(err) => { if(err){ console.log(err) }else{ console.log(req

Anyway to unzip a file uploaded in memory using Multer?

青春壹個敷衍的年華 提交于 2021-01-29 20:23:15
问题 I am using Multer to take a file uploaded on a form and keep it in memory so that I can parse it and spit out some stuff, but is there a way I can take in a zip file and be able to unzip it and still keep the unzipped files in memory without writing to a disk? I know there is an npm module for node called 'unzip', but it seems to only be able to pull a file from a physical location, unless I am mistaken. I appreciate any insight! const multer = require('multer'); const storage = multer

Does the free tier of Heroku apps support file upload?

耗尽温柔 提交于 2021-01-29 10:42:00
问题 I am testing out a MEAN stack application. I have a Node.js backend which handles file upload (via fs/multer ). However I'm receiving a 503 error when trying to hit it in production. Locally everything is working fine. I am using Heroku's free tier; is that tier locked to not allow file upload? The upload I'm trying currently (have tried several) is only 36kb ( .png ). Went through my logs and found the 503- 2018-10-26T20:39:24.352297+00:00 heroku[router]: at=error code=H13 desc="Connection

Why is req.file “undefined” for me when trying to upload a file using multer?

断了今生、忘了曾经 提交于 2021-01-29 06:28:44
问题 I'm trying to allow a user to upload a file using a form, then the image is supposed to be handled using multer in my controller file. For some reason, when I use upload.single('foobar'), it's coming back as "undefined," and screwing up the rest of my application. Specifically, when I run the code, my error handler in the createTour.js file returns an alert that reads "Cannot read property 'imageCover' of undefined". Any help would be appreciated. If helpful, here's the GitHub. Here's the

Why is req.file “undefined” for me when trying to upload a file using multer?

ε祈祈猫儿з 提交于 2021-01-29 06:23:06
问题 I'm trying to allow a user to upload a file using a form, then the image is supposed to be handled using multer in my controller file. For some reason, when I use upload.single('foobar'), it's coming back as "undefined," and screwing up the rest of my application. Specifically, when I run the code, my error handler in the createTour.js file returns an alert that reads "Cannot read property 'imageCover' of undefined". Any help would be appreciated. If helpful, here's the GitHub. Here's the

Upload file using multer after specific database operation in node js

房东的猫 提交于 2021-01-28 09:02:23
问题 I am using multer to upload files via express . Is there a way to perform a database operation before uploading the file? I need to perform a conditional check whether the user insertion in the database was successful or not depending on that, the file upload should be performed. 回答1: To use multer as per required you can use the following code: var path = require('path'); var multer = require('multer'); var storage = multer.diskStorage({ destination: function(req, file, callback) { callback

Upload file using multer after specific database operation in node js

我的未来我决定 提交于 2021-01-28 08:43:35
问题 I am using multer to upload files via express . Is there a way to perform a database operation before uploading the file? I need to perform a conditional check whether the user insertion in the database was successful or not depending on that, the file upload should be performed. 回答1: To use multer as per required you can use the following code: var path = require('path'); var multer = require('multer'); var storage = multer.diskStorage({ destination: function(req, file, callback) { callback

Node.js connection reset on file upload with multer

a 夏天 提交于 2021-01-28 03:26:57
问题 I have a node/express app that handles file uploads with multer. Everything works well on my local machine, but on the server, if the uploaded file exceeds a couple of Mbs, the browser stops with a "connection reset" error. Here is a simple test version of the upload script: var express = require('express'); var multer = require('multer'); // Create server var app = express(); // Start server function startServer() { var port = 8888; server = app.listen(port, function () { console.log('Node

multer, react native image picker image upload not working on iOS

北城以北 提交于 2021-01-28 00:46:16
问题 I am having great trouble in uploading an image via fetch and react-native-image-picker to multer and express js backend. Below is my react native code. try { const data = new FormData(); data.append('image', { name: photo.fileName, type: photo.type, uri: Platform.OS === 'android' ? photo.uri : photo.uri.replace('file://', ''), }); data.append('id', id) fetch(`${API}save-image`, { method: 'POST', body: data, }) .then(response => response.json()) .then(response => { console.log('upload succes'

Multer image upload in Nodejs and Express

谁说我不能喝 提交于 2021-01-27 18:41:11
问题 I've been trying for days to upload an image using Multer. This is how far I got. I tried multiple things, and can't seem to make it work. I don't know how to use Multer to upload an image in my createUser function in the format shown below. My ' server.js ' file: var express = require('express'); var multer = require('multer'); var upload = multer({dest: 'uploads/'}); var router = require('./app/routes'); var bodyParser = require('body-parser'); var mongoose = require('mongoose'); var