wood burning stoves 2.0*
The moose likes Servlets and the fly likes Browse- need full file path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Browse- need full file path" Watch "Browse- need full file path" New topic
Author

Browse- need full file path

saipraneeth nallapareddy
Ranch Hand

Joined: Dec 02, 2009
Posts: 159
hello everyone,

i want to upload a file to a server, so i am using the input tag with type attribute as file and when clicked on the submit button i am getting only the file name but not its full file path.

So can anyone tell me how to get the file path along with file name.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What enctype does your form use?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
saipraneeth nallapareddy
Ranch Hand

Joined: Dec 02, 2009
Posts: 159
i have not used any but the server on to which i upload takes care of it.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not sure I understand. How are you telling the browser that the request sent from your form includes the binary content of a file?
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

What makes you think that you should be able to get the full file path of the uploaded file? If I was uploading a file from my computer to you does it matter to you whether I uploaded it from "C:\sean\secret-files\data.dat" or "E:\data\shared\data.dat"? No, I don't think it would.

Maybe it wrong here, so if you could maybe provide some more information and perhaps the code in the servlet?

Sean


I love this place!
saipraneeth nallapareddy
Ranch Hand

Joined: Dec 02, 2009
Posts: 159
Actually i am able to upload thinking the source location remains the same and going ahead to upload the file, and more over the server on to which i am uploading has a webdav application running on it, so it handles the incoming file whether
application/x-rar
application/pdf
..
..
etc

is it exactly what you are talking about or any other. If so please let me know what else to be specified.
saipraneeth nallapareddy
Ranch Hand

Joined: Dec 02, 2009
Posts: 159
@Sean Clark
You are right, in the case you have said the upload code goes like streaming the bits of the file but i am not doing it in that way.
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

saipraneeth nallapareddy wrote:@Sean Clark
You are right, in the case you have said the upload code goes like streaming the bits of the file but i am not doing it in that way.

Ok, I'm not sure I understand, how can you upload a file without sending the file. Am I missing something here?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

saipraneeth nallapareddy wrote:Actually i am able to upload thinking the source location remains the same and going ahead to upload the file, and more over the server on to which i am uploading has a webdav application running on it, so it handles the incoming file whether
application/x-rar
application/pdf
..
..
etc

is it exactly what you are talking about or any other. If so please let me know what else to be specified.


I don't understand what you are saying here. How can the server define the enctype of the client request? If you are not following have a read of enctype in the HTML spec.

I'm with Sean too, I can't understand how you are uploading the file. Can you explain?
saipraneeth nallapareddy
Ranch Hand

Joined: Dec 02, 2009
Posts: 159
ok here is the code


this is a stand alone application, i have embedded this into jsp which receive the file name , now what i also want is it's path as well.

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


i have embedded this into jsp which receive the file name , now what i also want is it's path as well

How is that code going to run on the client?
saipraneeth nallapareddy
Ranch Hand

Joined: Dec 02, 2009
Posts: 159
come on paul, this is for your understanding how i am doing the upload, i made the required changes for it to run and upload it.
If you want i will give the jsp's well, but it looks similar.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

I'm asking because you have already said:

the upload code goes like streaming the bits of the file but i am not doing it in that way.

so I don't understand how you are performing your upload. The code you posted to explain this is a Java client to make a post request to a server, but you mention forms and inputs which sounds like you are have an HTML GUI. Given the client code contains virtually no functionality you would use for the server side part I'm not sure what it tells us?
saipraneeth nallapareddy
Ranch Hand

Joined: Dec 02, 2009
Posts: 159
I am sorry if my words doesn't make sense but i am thankful to you all taking the pain to solve my problem here are the two jsp's i used, where the former one will browse for the file and later will upload the file(upload code is here).


Success.jsp
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

saipraneeth nallapareddy wrote:



I think the OP is using a PUT request rather than a POST, which may be where the confusion is coming in.

I haven't really ever had reason to use PUT requests, so not sure how they work... but I really don't think you will be able to get the full file path from where the file was uploaded.

Sean
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

OK - that's easier to understand

Your form has no enctype attribute so will be using the default application/x-www-form-urlencoded. you will need to change this to multipart/form-data if you have an input wit hthe type "file".

Your success JSP cannot upload a file, because it is running on the server. It does not have access to the client machine's file system. So the part that actually does the uploading is still missing I think.
saipraneeth nallapareddy
Ranch Hand

Joined: Dec 02, 2009
Posts: 159
@Sean Clark
yes actually it is to a webdav server which will have the http way of communicating for reading and writing as well.
saipraneeth nallapareddy
Ranch Hand

Joined: Dec 02, 2009
Posts: 159
Paul Sturrock wrote:
Your "upload" JSP cannot upload a file, because it is running on the server. It does not have access to the client machine's file system.


No paul it will, I'm able to do it, the jsp's i gave your are running on a different server and the url(http://localhost) i have included in the jsp is being listened by another server, where a webdav application is running which supports http read and write as well
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Well, its an odd way to do this, but I'll take your word for it.

An input of type file will not give you the full path - this is not what it is designed to do. User agents can implement file select control as they like, so some may give you the entire file path, some may not. You can't work round this without using some sort of client side technology that runs outside the browser sand box (e.g. ActiveX or a signed Applet) which would let you browse the client file system. Why WebDAV for uploads?
saipraneeth nallapareddy
Ranch Hand

Joined: Dec 02, 2009
Posts: 159
Paul Sturrock wrote:
An input of type file will not give you the full path


I don't want to confined to input tag, can you suggest any other that do this with full file path as well.

Paul Sturrock wrote:
Why WebDAV for uploads?

It is not just for uploads but we have the things to view and making it more easier to download and upload like a windows explorer and this is just an experiment and it will undergo lot of changes.

@Paul Sturrock,Sean Clark
Thank you for your replies
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

If you need access to the client file system you'll need to use something that steps outside of the browser sand box. Such things tend to be ActiveX or similar equivalent. Have you considered a stand alone Java client rather than a browser based application? Might be an idea if the browser is preventing you doing things you need to do.
 
 
subject: Browse- need full file path
 
Similar Threads
escaped absolute path not valid
how to pass bundle full path to ResourceBundle ?
problem in running exec() from servlet
problem with the File upload
specify relative path in File constructor