[prev in list] [next in list] [prev in thread] [next in thread]
List: struts-user
Subject: Re: Unable to open uploaded pdf and docx file
From: Lukasz Lenart <lukaszlenart () apache ! org>
Date: 2024-03-28 15:04:17
Message-ID: CAMopvkM-2BkbrZrq8zi9gTpK9wao0KoRHMOef2dPE7ptgJJAGQ () mail ! gmail ! com
[Download RAW message or body]
śr., 27 mar 2024 o 02:01 Mahabir Gupta <mahabirg81@gmail.com> napisał(a):
>
> Dear Lukasz,
>
> Uploaded files are ok (access them on the server side once they have been
> uploaded). The MD5 for the uploaded file to the server and the downloaded
> file from the server is different. There is a decrease in the number of kb
> when the file is downloaded. The MD5 changed when it passed through the
> following code.
>
> ServletOutputStream out = null;
> FileInputStream fi = null;
> try {
> out = response.getOutputStream();
> fi = new FileInputStream(f);
> byte[] buffer = new byte[(int)f.length]; // Set the buffer size to
> 4KB or any suitable size
>
> int bytesRead;
> while ((bytesRead = fi.read(buffer)) != -1) {
> out.write(buffer, 0, bytesRead);
> }
> } catch (FileNotFoundException e) {
> e.printStackTrace();
> logger.info("File not found error" + filename);
> logger.error(e.getMessage());
> } catch (IOException e) {
> logger.info("Error in reading file:" + filename);
> } finally {
> if (out != null) safeClose(out);
> if (fi != null) safeClose(fi);
> }
This code isn't related to Struts and as far I see you are missing
.flush() operation
https://github.com/apache/struts/blob/master/core/src/main/java/org/apache/struts2/result/StreamResult.java#L282
Cheers
Lukasz
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic