• Post Reply Bookmark Topic Watch Topic
  • New Topic

upload file into right folder  RSS feed

 
Sunil K Bansal
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Chris Baron
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sunil K Bansal
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chris Baron
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sunil K Bansal
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chris Baron
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you use an upload bean like
jspsmartupload or multipartrequest ?
[ June 05, 2003: Message edited by: Chris Baron ]
 
Sunil K Bansal
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Petterson
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For SmartUpload go to this URL
http://www.jspsmart.com/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!