Forums Register Login

upload file into right folder

+Pie Number of slices to send: Send
Hi Guys,
I want to upload a file from client to server
i m using tomcat server..
if i need to upload a file I need t give path like this in
FileOutputStream fos = new FileOutputStream(new File("../webapps/examples/bhi/demos/"+file_to_upload));
my JSPs are in bhi folder. I have one more folder demos in bhi, i want to upload files into that..
by above i can upload the file..
but now if I switch to weblogic server.. this above "../webapps/examples/bhi/demos/" will not work..
in weblogic i hv put my JSPs in weblogic/myserver/public_html/bhi.., hence works
now please tell me, what path i shud write that my file get uploaded in right folder under, where my JSPs are..., which ever Server I choose
i hope u understand my problem, please give me the solution.. for independent of server
Thanks in anticipation.
Sunil Bansal
[ June 04, 2003: Message edited by: Sunil K Bansal ]
+Pie Number of slices to send: Send
Hi Sunil,
try application.getRealPath()
FileOutputStream fos = new FileOutputStream( new File( application.getRealPath( "/bhi/demos/"+file_to_upload" ) ) );
is /examples the webapp you are in ?
hth
+Pie Number of slices to send: Send
Hello Christian,
Thanks
it works...
i m facing onw more problem...
uptill now i was testing uploading of file from my m/c only .. means client and server was on same m/c
today i tried to upload from my colleague's m/c,
from 1 m/c it is working, i tried from 2-3 m/c more and it is not working..
but could be the reason.... here below is my code sample..
file_name="//"+request.getRemoteHost()+"/"+file_name;
int o=file_name.indexOf(':');
file_name=file_name.substring(0,o)+file_name.substring(o+1);
file_name=file_name.replace('\\','/');
int f=file_name.lastIndexOf("/");
newdemopath=file_name.substring(f+1);
int y;
String upload_file = application.getRealPath("/bhi/brochures/"+newdemopath);
FileInputStream fis = new FileInputStream(new File(file_name));
FileOutputStream fos = new FileOutputStream(new File(upload_file));
do
{
y=fis.read();
if(y !=-1)
fos.write(y);
}while(y !=-1);
fos.close();
fis.close();
thanks for help..
Sunil Bansal
+Pie Number of slices to send: Send
Hi Sunil,
sorry, can't imagine what you might to intent with:

here some useful methods that could help:

What upload class u use ?
In the O'Reilly servlet e.g. you specify the upload ( == save )Directory in the Constructor
and get the path 2 your File Object with
.get Filesystemname()
hth
[ June 05, 2003: Message edited by: Chris Baron ]
+Pie Number of slices to send: Send
Hello Chris,
actully I want to upload a file from any client m/c to server.
I cud not find the way to upload file to server.
in the above code, I m prefxing remote host m/c to the file name selected by the client in browser.
and the removing ":" from it..
say if file selected by user is
C:\some_folder\abc.doc
and his m/c address is, 89.0.0.876
i m trying to make this as,
//89.0.0.876/C/some_folder/abc.doc
then upload that file to server using input stream and outputstream.. but it seems it is not working..
can u help me in uploading a file from client m/c to server..
a sample code will be very helpful
Thanks..
Sunil Bansal
+Pie Number of slices to send: Send
Why don't you use an upload bean like
jspsmartupload or multipartrequest ?
[ June 05, 2003: Message edited by: Chris Baron ]
+Pie Number of slices to send: Send
Hello Chris,
what is this jspsmartupload or multipartrequest?
can u tell from where i can get this or send me at my id
sunilkbansal@indiatimes.com
thanks
Sunil Bansal
+Pie Number of slices to send: Send
For SmartUpload go to this URL
http://www.jspsmart.com/
On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1331 times.
Similar Threads
class object
Very argent file path
problem in uploading a file
ENCTYPE=multipart/form-data , input type=file
Writing a log file for my servlet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:38:03.