picture contest

/*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> 

Open in new window


what i need is how to query each image and server them to my clients every client sees a specifit image, and also get each image in a link such as localhost//3000/users/photos/234  so they can share links to thier images to recieve comments from friends etc as u can see i'm a newbie here thanks
princevladAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
A 'localhost' link can not be used from another computer.  'localhost' by definition is on the 'local' computer, the one that you are using.  You need an IP address or host name for people to access your page remotely.
1
princevladAuthor Commented:
thanks am still building on my computer so that was just an example, my main issue is to dynamically serve static files (images) to users.  i created an fs.readsync  to read all uploaded file and load them to my database but i want something like this
http://www.experts-exchange.com/questions/28697674/picture-contest.html#a40884428
a url that would link everyone to a particular image on my site
just like a you tube video link etc
0
Julian HansenCommented:
Trying to understand what the problem is?

I am guessing that this is a Node.js / Express.js question - you are asking how to pick up the URL and link that to a specific static resource on the server?

Is your question about how to parse the link or how to return the image?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

princevladAuthor Commented:
yes how to parse the link and return the image and yes is a node.js project

the attachment contains the fool upload code
0
Julian HansenCommented:
What attachment?

Trying to understand the relevance of the upload code to the problem at hand. As I understand it the upload part works and the file is saved somewhere on your server file system, yes?

If so you are now wanting a method to parse a link to that file and return the file - is that correct?

It sounds like you need to use the methods described here

http://expressjs.com/api.html

and specifically here

http://expressjs.com/api.html#app.METHOD
1
princevladAuthor Commented:
thanks
i was able to render a photo via url params but the url affects other buttons on my site example

localhost/photo/vote/01.jpg
it renders the photo in an html page but  when i click on VOTE or another button on the page it shows

cannot post photo/vote/vote
0
Julian HansenCommented:
That is because of relative paths.

You need to make your links absolute otherwise a link to
<a href="vote"> ...
On page
http://server/photo/vote

Will translate to http://server/photo/vote/vote

You have to do
<a href="http://server/photo/vote"> ...

Open in new window

Another (less desirable) option is to use the base tag like so
<base href="http://server" />

Open in new window

This will then prefix all relative links with the URL specified in the base ref tag.

There are some good reasons why this is not a desirable solution but it is valid and in will work.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.