[Opensource] Re: file uploads bug
larry hamel
expresso at codeguild.com
Wed Jan 15 13:44:00 PST 2003
hi Will,
bug 1 and 2 fixed in latest code. thanks for the solutions.
regarding 2), there are really only 2 streams, one of which wasn't closed. new code helps explain:
BufferedInputStream bin = null;
BufferedOutputStream bout = null;
try {
bin = new BufferedInputStream(new FileInputStream(sourceFile));
bout = new BufferedOutputStream(new FileOutputStream(destFile));
onechar = bin.read();
while (onechar != -1) {
bout.write(onechar);
onechar = bin.read();
}
} finally {
if ( bin != null ) bin.close();
if ( bout != null ) bout.close();
}
larry
At 10:26 PM 1/13/2003, you wrote:
>Oops, typo, solution one should be:
> OutputStream ops = item.getOutputStream();
> multi.readBodyData(ops);
> ops.close();
>
>will wrote:
>
>> FYI,
>>
>> I am working on an application build on Expresso 5.0.2. While attempting
>> to get the application to upload file using the built in Expresso
>> functionality I encountered a problem. Files were getting to the default
>> temp directory but once there, I could not delete them within the same
>> request.
>>
>> I think the following two items are bugs that you should be aware of:
>>
>> 1.
>> Method: com.jcorporate.expresso.core.misc.upload.Uploader.parseRequest(
>> HttpServletRequest, ParameterParser, path)
>>
>> Description: In three places your code does this:
>>
>> multi.readBodyData(item.getOutputStream());
>> The getOutputStream() method returns an OutputStream but I could not
>> find any code that closed this OutputStream.
>>
>> Solution: I changed my local file to this:
>> OutputStream ops =
>> item.getOutputStream();
>>
>> multi.readBodyData(item.getOutputStream());
>>
>> ops.close();
>>
>> 2.
>> Method: com.jcorporate.expresso.core.misc.FileUtil.copyFile(String,
>> String)
>>
>> Description: At the bottom of this method a buffer is flushed and two
>> OutputStreams are closed:
>> bout.flush();
>> bin.close();
>> fin.close();
>> Unfortunately there are four OutputStreams in this method.
>>
>> Solution: I changed my local file to this:
>> bout.flush();
>> bout.close();
>> fout.close();
>> bin.close();
>> fin.close();
>>
>> This solved the problem and allowed the uploaded file to be moved to a
>> permanent directory in the same request. Please let me know if there is
>> a better solution.
>>
>> Cheers,
>> Will
>
>_______________________________________________
>Opensource mailing list
>Opensource at jcorporate.com
>http://mail.jcorporate.com/mailman/listinfo/opensource
>Archives: http://mail.jcorporate.com/pipermail/opensource/
More information about the Opensource
mailing list