multer

node.js on heroku keeps losing image after a while

十年热恋 提交于 2019-12-11 18:28:36
问题 my Node.js app keeps losing static images(.jpg, .png...) after a while. It doesn't lose any images on my local win10 desktop and even on heroku, my webpack bundle.js is served from the same static route(/pub or /dist) and they work just fine. somehow only the static images, they are served alright for first few minutes when I first uploaded then after a while, it disappears. I am using express.static for static route declaration and multer for file upload. The files used for test were all

Node js Multer file upload with extra text input fields

半城伤御伤魂 提交于 2019-12-11 17:59:08
问题 I am trying to upload a file to disk using multer. Here is my code: const multer = require('multer'); var storage = multer.diskStorage({ destination: (req, file, cb) => { cb(null, __basedir + '/uploads/') }, filename: (req, file, cb) => { cb(null, file.fieldname + "-" + Date.now() + "-" + file.originalname) } }); var upload = multer({storage: storage}); And here goes my form to collect the file and some extra input fields <form method="post" enctype="multipart/form-data" action="/uploadfile">

Multer file.filename and file.path undefined

心不动则不痛 提交于 2019-12-11 15:27:54
问题 I'm trying to upload/store images on disk memory using express and multer. My code in a nutshell below: const express = require('express') const multer = require('multer'); const upload = multer({ destination: function(req, file, cb) { cb(null, 'uploads/') }, filename: function(req, file, cb) { cb(null, file.fieldname + '-' + Date.now()) } }); app.post('/', upload.single('photo'), function(req, res) { console.log(req.file); }); Unfortunately, when I use Postman to send a POST request (the

Multer access req.body without uploading files

巧了我就是萌 提交于 2019-12-11 06:07:25
问题 I have a form with some text fields and file inputs which cannot be empty, I want to do some operations with the text fields first(adding to database) and if these operations were successful then upload the files. This is my code right now : var multer = require('multer'); var getFields = multer(); router.post('/add',getFields.array(),function(req,res){ var artist = new ArtistModel({ name : req.body.name.toLowerCase(), description:req.body.description, }); I then add artist to my DB and in

Uploading images to S3 using NodeJS and Multer. How to upload whole file onFileUploadComplete

旧巷老猫 提交于 2019-12-11 02:45:19
问题 I'm using NodeJS and Multer to upload files to S3 . On the surface, everything appears to be working, the files get uploaded, and I can see them in the bucket when I log into the AWS console. However, most of the time when I follow the link to the file, the file is broken, often the file size is much smaller than the original file. When the file reaches the server, the file size is correct if I log it, but on S3 it is much smaller. For example I just uploaded a file which is 151kb. The post

Files not uploading with ng2-file-upload

耗尽温柔 提交于 2019-12-11 01:23:03
问题 I'm trying to implement this library to upload images to a folder server: When I click on "upload" button the server returns inmediately to the listener this.uploader.onCompleteItem on my fileUpload.ts component: ImageUpload:uploaded: FileItem {url: "http://127.0.0.1:5000/api/uploadPhoto", headers: Array(0), withCredentials: false, formData: Array(0), isReady: false…}alias: "file"file: FileLikeObjectformData: Array(0)headers: Array(0)index: undefinedisCancel: falseisError: falseisReady:

Upload a file in NodeJs with Multer and change name if the file already exists

浪尽此生 提交于 2019-12-11 00:37:51
问题 I need to upload a file from my client to a Node server (I use Multer to perform this task). The requirement is that if a file with the same name already exists on the server I need to change the name of the new file. I use Node fs.stat to check for the existence of a file with the same name. I must be doing something wrong since fs.stat always tells me that there is no file with the same name when in fact it is there (I end up overwriting the old file with the new one). Here is the code. var

Transform upload with NodeJS Multer

一笑奈何 提交于 2019-12-11 00:27:30
问题 I'm currently implementing a file/image upload service for my users. I want to transform these images (resize/optimize) before uploading to my s3 bucket. What I'm currently doing: Using a multipart form on my frontend (I think the actual implementation doesn't matter here..) and the multer and multer-s3 packages on my backend. Here my implementation stripped down to the important parts. // SETUP var multer = require('multer'); var s3 = require('multer-s3'); var storage = s3({ dirname: 'user

NodeJS Multer validate fields before upload

别说谁变了你拦得住时间么 提交于 2019-12-10 18:29:27
问题 I'm trying to validation my form before i upload images but i getting empty string on my middleware const upload = multer({ storage: storage }); router.post('/upload', formsValidation, upload.fields([{ name: 'images', maxCount: 20 }, { name: 'imageMain', maxCount: 1 }]), function(req, res, next) { code... }); heres my middleware: function formsValidation (req, res, next) { console.log(req.body) //getting empty array here return next(); } i know that i can use fileFilter from multer but some

getting Error: Unexpected field when trying to upload multiple files

好久不见. 提交于 2019-12-10 17:45:52
问题 If I use the example in multer's readme, I can upload a single file without problems. However, when I use the same sample I cannot do so for multiple files. I tried using the regular Error: Unexpected field at makeError (/Users/mroker/node_projects/JWT_Auth_Basic/node_modules/multer/lib/make-error.js:12:13) at wrappedFileFilter (/Users/mroker/node_projects/JWT_Auth_Basic/node_modules/multer/index.js:39:19) at Busboy. (/Users/mroker/node_projects/JWT_Auth_Basic/node_modules/multer/lib/make