A further issue with javax.servlet.http.Part - given the following sequence:
Part foo = request.getPart("foo");
foo.write("foo.txt");
InputStream foostream = foo.getInputStream();
The behaviour will differ depending on the container's implementation
of Part.write() method.
The javadoc for Part.write() says:
"This method is not guaranteed to succeed if called more than once
for the same part.
This allows a particular implementation to use, for example, file
renaming, where possible,
rather than copying all of the underlying data, thus gaining a
significant performance benefit."
So if the container implements Part.write() as a rename,
foo.getInputStream() will fail, because the tmp file no longer exists,
as it has been renamed to "foo.txt". However, if the container
implemented Part.write() as a copy, foo.getInputStream() will succeed,
because the tmp file still exists.
Moreover, I think it likely that users will do the call sequence
above, because it looks intuitively straightforward (save the file,
then get its bytes), and there's nothing in the javadoc or spec that
warns them it may not work. Can we please clarify the spec so that the
behaviour is consistent across containers?
Jan
On 5 October 2012 18:58, Jan Bartel <janb_at_intalio.com> wrote:
> Hi,
>
> If I retrieve the parts of a multipart mime request with
> Request.getPart(x), and I later go on to call Part.write("foo.file"),
> what is the expectation of the permanency of the subsequently written
> file? Will it exist after the request has exited the container? Will
> it exist after the container's jvm has exited?
>
> Indeed, is the expectation that any of the parts retrieved which may
> have been written to a file - eg because of a
> MultipartConfigElement.fileThresholds value - are available (a) after
> the request has exited, (b) after the container's jvm has exited?
>
> thanks,
> Jan
> --
> Jan Bartel <janb_at_intalio.com>
> www.webtide.com – Developer advice, services and support
> from the Jetty & CometD experts.
--
Jan Bartel <janb_at_intalio.com>
www.webtide.com – Developer advice, services and support
from the Jetty & CometD experts.