views:

188

answers:

2

Whenever I try to attach any file from HTML page in web browser(either Google chrome or Mozzila) and send to Servlet, I'm getting just getting the name of the file without having it's complete path. If I make an attachment of any file from C drive, I'm not getting it's complete address. And whenever I try to send this file name to mail server, I'm getting an exception:

Caused by: java.io.FileNotFoundException: Hello.txt (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at javax.activation.FileDataSource.getInputStream(Unknown Source)
    at javax.activation.DataHandler.writeTo(Unknown Source)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1381)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:852)
    at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:452)
    at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:98)
    at javax.activation.ObjectDataContentHandler.writeTo(Unknown Source)
    at javax.activation.DataHandler.writeTo(Unknown Source)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1381)
    at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1742)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:737)
    ... 18 more

How can I get rid of this problem? How to get the complete address of my uploaded file?

+2  A: 

Even if you were to obtain the full path, it would be the path of the file on the client's machine, which the server has no access to.

If you want to store the uploaded file on the server, then you need to store the uploaded file on the local server filesystem, then pass that to the JavaMail API.

skaffman
A: 

To the point: you should not send the file path, but you should send the file contents.

Imagine that I am the server and I have a file path "c:/passwords.txt" here at my local disk system, can you as being the client tell me what its contents are?

BalusC