Reputation: 45
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());
}
} }
Upvotes: 2
Views: 462
Reputation: 10373
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 OutputStream
s.
Upvotes: 1