Hi, I'm using node.js (express & mongoose) as a backend API server for an iPhone client. The iphone will upload binary data such as images and short audio clips to the server. I'm confused about how to save these into the mongodb using Mongoose. It seems that I should be using gridfs, but the gridfs-stream module that I found is difficult for me to understand (I'm day 5 on node, sorry).Any help would be great!
--
--
http://mongoosejs.com - docs
http://plugins.mongoosejs.com - plugins search
http://github.com/learnboost/mongoose - source code
You received this message because you are subscribed to the Google
Groups "Mongoose Node.JS ORM" group.
To post to this group, send email to mongoo...@googlegroups.com
To unsubscribe from this group, send email to
mongoose-orm...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/mongoose-orm?hl=en
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
A quick search on plugins.mongoosejs.com also turned up these options. There's probably more out there too:
{
...
"dependencies": {
...
"mongoose": "*",
"mongoose-file": "*",
"mongoose-thumbnail": "*"
}
}
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/sample');
var thumbnailPluginLib = require('mongoose-thumbnail');
var thumbnailPlugin = thumbnailPluginLib.thumbnailPlugin;
var PictureSchema = new mongoose.schema({
title: String
});
PictureSchema.plugin(thumbnailPlugin, {
name: "photo",
inline: false
});
var Picture = db.model("Picture", PictureSchema);
app.post('/upload', function(req, res, next) {
var picture = new Picture({ title: req.body.title });
picture.set('image.file', req.files.image);
picture.save(function(err) {
if (err) {
return next(err);
}
});
res.redirect('/');
});
extends layout
block content
div
form(action='/upload', method='POST', enctype='multipart/form-data')
input(type='file', name='image')
input(type='submit', value='Upload')
{ "photo" : { "thumb" : { "rel" : null, "path" : null, "name" : null }, "lastModified" : null, "size" : null, "type" : null, "rel" : null, "path" : null, "name" : null }, "_id" : ObjectId("52526bd755b5711a23000001"), "__v" : 0 }
Hi, Marco.mongoose-file and mongoose-thumnail are very simple, awesome!I want to use your mongoose-plugins.
but, doesn't work it my hope from express.js.
app.js:
PictureSchema.plugin(thumbnailPlugin, {
name: "photo",
inline: false
});
var Picture = db.model("Picture", PictureSchema);
app.post('/upload', function(req, res, next) {
var picture = new Picture({ title: req.body.title });
picture.set('image.file', req.files.image);
picture.save(function(err) {
if (err) {
return next(err);
}
});
res.redirect('/');
});
/home//node_modules/mongoose-file/lib/index.js:120
throw err;
Error: EXDEV, rename '/tmp/2330-5ezme8.jpg'
npm ERR! weird error 8
npm ERR! not ok code 0
> use mongoose-thumbnail-example
switched to db mongoose-thumbnail-example
> show collections
pictures
system.indexes
> db.pictures.find()
{ "title" : "", "photo" : { "thumb" : { "rel" : null, "path" : null, "name" : null }, "lastModified" : null, "size" : null, "type" : null, "rel" : null, "path" : null, "name" : null }, "_id" : ObjectId("5254bf7507185d1a09000001"), "__v" : 0 }
Thanks for replay and mongoose-thumbnail-example created!I understand name field in Model and '/upload' handler.Rerun modified code, and then output error.
/home//node_modules/mongoose-file/lib/index.js:120
throw err;
Error: EXDEV, rename '/tmp/2330-5ezme8.jpg'
npm ERR! weird error 8
npm ERR! not ok code 0in the mongo collection.
> use mongoose-thumbnail-example
switched to db mongoose-thumbnail-example
> show collections
pictures
system.indexes
> db.pictures.find()
{ "title" : "", "photo" : { "thumb" : { "rel" : null, "path" : null, "name" : null }, "lastModified" : null, "size" : null, "type" : null, "rel" : null, "path" : null, "name" : null }, "_id" : ObjectId("5254bf7507185d1a09000001"), "__v" : 0 }Same error came out even mongoose-thumbnail-example.In order to exec the mongoose-thumbnail, node_module is also required else?
Or, '/tmp' is require root permission...?
Pls mail me your sample code , it'll be very helpful for me!
--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to a topic in the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongoose-orm/H-8JLNyivcc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongoose-orm...@googlegroups.com.
MarcoI just tried the vanilla code from your site but I always get something like:Error: EXDEV, rename 'C:\Users\teastwoo\AppData\Local\Temp\8196-1h2p967.log'and it crashes out. It creates an object in the in MongoDB but there is no image bytes.Have you any idea what I'm doing wrong? - I'm calling it from a Chrome client and the code is hosted on a local tomcat server