hi i used multer to create an upload script now i would like to display the photos uploaded by eacch user on diff pages with diff adrees i.e exprome.come/photos/234 and also every photo would have its comment. any ideas? i think every comment should be saved with the photo id so i can retrieve them but im a newbee here i would love to here your ideas

Member Avatar for diafol

Contributors will help you but this is rather vague. Show your code. What doesn't work? What errors are you getting?

what is the error? everything save in db and the uploaded picture in the same directory?

/*Define dependencies.*/

var express=require("express");
var multer  = require('multer');
var mongoose= require ('mongoose');
var app=express();
var done=false;

/*Configure the multer.*/

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)
  done=true;
}
}));

// routes

app.get('/',function(req,res){
      res.sendfile("index.html");
});

app.post('/api/photo',function(req,res){
  if(done==true){
    console.log(req.files);
    res.end("File upload complete.");
  }
});

// server
app.listen(3000,function(){
    console.log("listening on port 3000");
});



HTML file

<form id ="uploadForm" enctype="multipart/form-data" action =  "/api/photo"method= "post"
> <input type="file" name="userPhoto" />
<input type="submit" value="Upload Image" name="submit">
</form>

what i need is how to save the file part to mongodb using mongoose and also the image id, and also get each image in a link such as localhost//3000/users/photos/234

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.