Solved

com.oreilly.servlet question

Posted on 2001-06-22
6
213 Views
Last Modified: 2010-04-16
Hi everybody!

I am using the package com.oreilly.servlet for uploading files to my server.

What I wanted to do is upload an image that has a name but I want to save it in my server with another name.

I want to save the image:

client:  c:/images/image.jpg

and overwrite this image in the server in

server: c:/server/images/serverimage.jpg

is there any easy way to do it?

Thanks!

Pablo
0
Comment
Question by:pablete
  • 2
  • 2
  • 2
6 Comments
 
LVL 3

Expert Comment

by:jerelw
ID: 6219483
1. create your File with the name you want
2. get your InputStream
3. write the stream to the File

0
 
LVL 1

Expert Comment

by:goldwarlock
ID: 6219566
The name of 1st file has no connection with 2nd
All you need is to handle the Streams!
So jerelw is right
0
 
LVL 1

Expert Comment

by:goldwarlock
ID: 6219614
btw: visit my site
www.xanga.com/goldwarlock
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:pablete
ID: 6223867
Sorry about my lack of knowledge, but I don't know how to do that.

I am using the object MultipartRequest:

MultipartRequest(HttpServletRequest request ,String filePath , int size).

Constructor for class com.oreilly.servlet.MultipartRequest
Constructs a new MultipartRequest to handle the specified request, saving any uploaded files to the given directory, and limiting the upload size to the specified length.

Just creating the object the file is written, I don't get any parameters or anything, so I don't know how to handle the file.

Thanks again,

Pablo




0
 
LVL 3

Accepted Solution

by:
jerelw earned 200 total points
ID: 6225699
public static void writeToFile(String fileName, InputStream is) throws Exception {
    try {
     
       FileOutputStream fos    = new FileOutputStream(new File(fileName));          
       BufferedInputStream bis = new BufferedInputStream(is);          
       
       int c = 0;          
       
       while ((c = bis.read()) != -1) {              
         fos.write(c);          
      }
       fos.flush();
       fos.close();
    }
     catch(Exception e) {
       throw new Exception("Err Writing Contents: " + e);
     }    
  }

use request.getInputStream();

to get your InputStream
0
 

Author Comment

by:pablete
ID: 6226802
Cheers!

Pablo
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question