2

Is that possible to upload a file into 2 different folders in the same time ? The problem I'm having is i can only upload 1 file into 1 folder only.

try{
    private String uploadPathBig = "D:/dataBig/";
    private String uploadPathSmall ="D:/dataSmall/";
    private int maxFileSize = 1024 * 1024 *100000 ;

    MultipartParser parser = new MultipartParser(request,maxFileSize); 
    Part _part = null;

    if ((_part = parser.readNextPart()) !=null){
        if (_part.isFile()){
            FilePart fPart =(FilePart) _part;
            fPart.writeTo(new java.io.File(uploadPathBig)); 
            String name = fPart.getFileName();
            System.out.println("name="+name);
        }


    }
}catch (java.io.IOException ioe){
    throw new java.io.IOException("IOException occureed in:"+ getClass().getName());
 }

} }

1
  • 2
    After the file is uploaded to a folder, copy it to the others as you would normally do with Java. Commented Oct 7, 2014 at 8:03

1 Answer 1

1

The simplest solution would be to copy the file to the second location after uploading as SJuan76 suggested.

It seems, you are using the O'Reilly MultiPartParser library. It would be nice to mention the use of a non-standard library next time.

To upload the file to two different locations at the same time you can use the FilePart.getInputStream() method instead of writeTo(). Then open a FileOutputStream for each target file and copy the bytes from the InputStream to the two OutputStreams.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.