Solved

com.oreilly.servlet question

Posted on 2001-06-22
6
212 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now