gridfs-stream

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

杀马特。学长 韩版系。学妹 提交于 2019-12-22 10:39:39
问题 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

File download is not working with nodejs gridfs

我的梦境 提交于 2019-12-12 09:17:00
问题 i'm uploading images to gridfs-stream using node and express..uploading is working fine but am unable to download app.post('/upload', function (req, res) { var tempfile = req.files.displayImage.path; var origname = req.files.displayImage.name; var _id = guid(); var writestream = gfs.createWriteStream({ filename: _id }); // open a stream to the temporary file created by Express... fs.createReadStream(tempfile) .on('end', function () { res.send(_id); }) .on('error', function () { res.send('ERR'

MEAN : Serve File from GridFs

北战南征 提交于 2019-12-11 16:08:21
问题 I am using MEAN stack and I am trying to serve a file stored using Mongo GridFs. This is the code I have tried so far. exports.getFile = function(req, res) { var fileId = req.params.fileId; gfs.findOne({ _id: fileId }, function (err, file) { if (err) { res.status(500).send(err) } console.log('file meta', file); res.header("Content-Type", file.contentType); var readstream = gfs.createReadStream({ filename: file.filename }); //error handling, e.g. file does not exist readstream.on('error',

Stuck at changing binary data to base64 (Gridfs-stream)

我们两清 提交于 2019-12-11 12:31:57
问题 I am trying to change some binary data from my uploaded images to base64 so I can use that to display an image. But the terimal is giving me this error: TypeError: Cannot read property 'on' of undefined I don't understand, when I post I also use the .on event and it is working fine. Besides that, I wonder if I am correctly changing the data. Please take into account that I'm fairly new to node :) How I save a uploaded image (POST) // Post to profile page router.post('/', function(req, res,

Reading and Displaying images from mongoDB using GridFs

*爱你&永不变心* 提交于 2019-12-09 01:35:00
问题 I have been able to successfully upload images to mongoDB using GridFs. Below are images from my database: fs.files: fs.chunks: Below is the code I used to upload images: var Grid = require('gridfs-stream'); var mongoose = require("mongoose"); Grid.mongo = mongoose.mongo; var gfs = new Grid(mongoose.connection.db); app.post('/picture', function(req, res) { var part = req.files.filefield; var writeStream = gfs.createWriteStream({ filename: part.name, mode: 'w', content_type:part.mimetype });

Gridfs and mongoose file upload

瘦欲@ 提交于 2019-12-08 13:29:25
问题 I have ran into a problem with gridfs file upload. Basically I get this bizzare error and I have yet not found solution for solving this problem. Here is my code that should deal with file upload: var path = require('path'); var router = require('express').Router(); var mongoose = require('mongoose'); var serverConfig = require('../config.js'); var multiparty = require('connect-multiparty')(); var fs = require('fs'); var GridFs = require('gridfs-stream'); var db = mongoose.connection.db; var

stored files directly in mongodb with gridfs-stream

杀马特。学长 韩版系。学妹 提交于 2019-12-06 15:27:25
问题 I need save some files like: images,video,pdf... into mongodb, so i use gridfs-stream and express.js var file = req.files.file; req.pipe(gfs.createWriteStream({ filename:file.originalname, mode:"w", chunkSize:1024*4, content_type:file.mimetype, root:"fs" }) res.send(200); for testing i use postman and set an POST request this way: POST /fs/upload HTTP/1.1 Host: localhost:5000 Cache-Control: no-cache ----WebKitFormBoundaryE19zNvXGzXaLvS5C Content-Disposition: form-data; name="file"; filename=

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

stored files directly in mongodb with gridfs-stream

旧巷老猫 提交于 2019-12-04 21:21:56
I need save some files like: images,video,pdf... into mongodb, so i use gridfs-stream and express.js var file = req.files.file; req.pipe(gfs.createWriteStream({ filename:file.originalname, mode:"w", chunkSize:1024*4, content_type:file.mimetype, root:"fs" }) res.send(200); for testing i use postman and set an POST request this way: POST /fs/upload HTTP/1.1 Host: localhost:5000 Cache-Control: no-cache ----WebKitFormBoundaryE19zNvXGzXaLvS5C Content-Disposition: form-data; name="file"; filename="epic.png" Content-Type: image/png ----WebKitFormBoundaryE19zNvXGzXaLvS5C the problem is that this way

How to send an retrieved image from Mongo using GridFS in Spring Rest Call?

左心房为你撑大大i 提交于 2019-12-04 13:41:24
问题 I have retrieved the image from Mongo DB using Spring Data and GridFs Template so i don't know how to serve that retrieved input stream back to user . Say they requested for the http://host.com/apple as a spring rest call . Now my application process the request by using the name apple it retrieves the apple image from a mongodb database . Now without saving anywhere i want to display the response as an image to user that will show http://host.com/apple image in the browser. How exactly i