-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Konstantin,

On 3/26/20 18:44, Konstantin Kolinko wrote:
> чт, 26 мар. 2020 г. в 18:03, Christopher Schultz
> <ch...@christopherschultz.net>:
>>
>> All,
>>
>> I'm developing my first multipart handler since .. I dunno,
>> maybe 2005? This is the first time I'll be using the Servlet 3.0
>> multipart handling, of course through Tomcat. Some of these
>> questions may have answers which are "implementation-specific",
>> so in this case, I would like to know how things will behave in
>> Tomcat specifically. Notes of where the spec leaves things up to
>> the implementation will be appreciate d.
>>
>> I'd like to submit a form which has not only a large-ish file
>> part, but also some regular fields like <input type="text">. My
>> understanding is that I'll have to read those data by calling
>> Part.getInputStream(), wrapping the InputStream in an
>> InputStreamReader using the right charset, etc.
>
> I think that those are available via the standard
> request.getParameter(name) API.

That doesn't work. Mixing request.getParameter() and request.getParts
results in request.getParameter* returning nulls.

>> Can I rely on the client to send the fields in any particular
>> order? I'm not expecting to store the file on the server myself;
>> I'd like to process it in a "streaming" fashion and not touch the
>> disk if possible. I know that the server may store the file on
>> the disk if it decides to. I'm not terribly worried about that. I
>> just don't want to have to write the file to the disk TWICE, and
>> I need information from those other parameters in order to
>> configure the stream-processing.
>
> Michael already answered this. There is a configurable threshold.
> Anything over it will be written to disk as a temporary file.
>
> The JavaDoc for Part.write() says that it can be implemented as
> moving the file. "This method is not guaranteed to succeed if
> called more than once"
>
>> When iterating over the Collection<Part> returned from
>> HttpServletRequest.getParts(), am I required to process each part
>> in order immediately? Or can I store a reference to a Part for
>> later? This kind of goes along with the previous question.
>
> You can store the reference, but your "for later" should be no
> longer than until the request processing ends.

Oh, of course. I shouldn't have left that detail unaddressed. I just
meant that I wanted to process all the parts and then handle the large
file, to make sure I had all the "small" fields read.

>> When I'm done with a part, must I explicitly call Part.delete()?
>
> Tomcat deletes the files automatically (I implemented this feature
> in Tomcat 7.0.30 - see changelog). In my own web applications I
> delete the files explicitly (calling part.delete() in a cycle).

I may go ahead and store a reference to the Part which represents the
large file and explicitly call Part.delete() on it, just to be sure.

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl5+IScACgkQHPApP6U8
pFinYxAApRdIDNNNxlkb5HIrPgKlCpQ9B5I5r+ceFD4GeylFZ1NodG3pxCv/E/C1
xxpjHiYv5dS30LIsZzLUe3PEnegWefokDKWLviKak54MFyQqkmmD3iEKypCp4F2y
HwXFDKhBRea/D1j/kwXLmfW8FSKM9lZCN23rLmYl2O0YrKqCnaFf9PJqcSBAqBnx
9vfW6RQEdRsALuHMGurdSV9hJDqCZ+l0298bweR3C4DuIpiM5EorNkf4vOrKvOpn
078sxpFtVDrxfwQ7gltagCPmFoNxcTX83h8oYAmb+aso7xeXlCQTIbkHbQV3qR4t
fOj1pFc2ZhP9U0wR4obD8Uwhpo8bVDcOsSVXBHGJSGMeCjdiaPmXL80C+fBtAT7i
0xtb92fjZRvyEwN/yWHjmE05dJiMh8sI0rs6cfXi34QtP8AW14VIKNed/BCmYD/F
LFw5OtBP0GRC1nENwRHmFIWeqFw48xB+rqSBPMoquA4YRBVekEWlvIeAzCBFmYMb
XkUv38Vj73Z9mHD/9VQnXTa0/KJjZhVeLrl77reB6fLdEyBnACGVgJR/HpBwtdV6
QhuUFHkPhl3mLP6weoKLyj8RbiJt11eKQ6XAt9iaaSiehpwzh2Q2BWJ0ckuRqbH1
KoXbFdYBur8Cg2OQVfjArnuX3yFSos1Ew7+MjzEQ3bnCZrgb2o8=
=Lekc
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to