Solved

com.oreilly.servlet question

Posted on 2001-06-22
6
211 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

757 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

19 Experts available now in Live!

Get 1:1 Help Now