You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Laurent Duparchy <du...@esrf.fr> on 2006/10/02 10:11:05 UTC
Re: FormFile getPath() ?
Hi,
thanks but the reply but I think it does exactly what I want to avoid
(and what I'm currenlty doing) : Create a second temp file by reading
the inputsream into a new FileOutputStream.
I'm looking into the possibility to get the filepath (when exist) of the
FormFile, not the inpustream.
Mark Shifman wrote:
> An action like this should do it:
> public final class UploadAction extends Action {
> public ActionForward execute( ActionMapping mapping, ActionForm form,
> HttpServletRequest request, HttpServletResponse response)
> throws Exception {
>
> UploadForm theForm = (UploadForm) form;
> FormFile file = theForm.getTheFile();
> String fileName = file.getFileName();
>
> try {
> String filePath =
> tempdir + "/" + fileName;
> //retrieve the file data
>
> InputStream stream = file.getInputStream();
>
> //write the file to the file specified
> OutputStream bos = new FileOutputStream(filePath);
> int bytesRead = 0;
> byte[] buffer = new byte[8192];
> while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
> bos.write(buffer, 0, bytesRead);
> }
> bos.close();
> //close the stream
> stream.close();
> } catch (Exception ex) {
> throw ex;
> }
>
> file.destroy();
>
> return (mapping.findForward("anywhereyouwant");
>
> }
> Laurent Duparchy wrote:
>
>> Hi,
>>
>> My front-end program upload files and then forward the file path to
>> another server side program that handle them.
>>
>> The problem is that I have to read the FormFile data and store it
>> into another temp file.
>>
>> It would increase performances this data duplication and have access
>> directly to the Struts temp file.
>>
>> I can't see how.
>>
>> I understand that there is maybe no file at all, as a small size a
>> file will be stored in memory, but is the maybe existing underlying
>> FileItem avaiable in anyway ?
>>
>> Laurent
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org