Expand my Community achievements bar.

SOLVED

Page forward doesn't happen when the file size is larger than 5 mb

Avatar

Level 2

1. I have a form with multipart/form-data which posts to a servlet.

2. The servlet processes the request and forwards to a page.

I have written a custom servlet that extends a SlingAllMethodsServlet.

In the servlet I am checking wether it is a multi part 

try
        {
            
            if(ServletFileUpload.isMultipartContent(request))
            {
                List<File> attachedFiles = new ArrayList<File>();

                Map<String, RequestParameter[]> params = request.getRequestParameterMap();
                Map<String, String[]> parameterMap = null;

                for ( Map.Entry<String, RequestParameter[]> pairs : params.entrySet()) 
                {
                    String key = pairs.getKey();

                    if(key.equals("fileName1") || key.equals("fileName2") || key.equals("fileName3"))
                    {
                        RequestParameter[] paramArray = pairs.getValue();
                        if(paramArray != null && paramArray.length > 0)
                        {
                            RequestParameter param = paramArray[0];
                            
                            InputStream inputStream = param.getInputStream();

                            if(inputStream.available() != 0)
                            {
                                final File tempFile = File.createTempFile(PREFIX, SUFFIX);
                                tempFile.deleteOnExit();
                                try (FileOutputStream outputStream = new FileOutputStream(tempFile)) 
                                {
                                    IOUtils.copy(inputStream, outputStream);
                                }
                                
                                attachedFiles.add(tempFile);

                                forwardToThankYouPage(request, response, thankYouPagePath);

 

                            }

                        }
                    }

                }

 

for some reason the  forwardToThankYouPage does not work when the file size is larger than 1 mb. For files of 100bytes the process run's just fine.

Can some one help me figure out.

Thanks,

depath

1 Accepted Solution

Avatar

Correct answer by
Level 3

Hello depath,

Can you attach the error.log file for the use case when the file size is larger than 1 mb ?

[EDIT] Let me suggest you an alternate approach for your usecase,

  1. Rather than sending the file binary data to the servlet, you can first upload the file to a temp path and then create an attribute in the request containing this file path which is available to the servlet.
  2. Now, in the servlet, you can use this path to access the binary contents.
  3. This approach would always work because you are never dependent on file size anywhere, the file gets uploaded first in a temporary path(using sling post servlet)[1] and then you use this path to access the file contents.

Let me know your thoughts.

Thanks

[1] http://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-pos...

View solution in original post

2 Replies

Avatar

Level 10

Hi depath,

     Make use of copyLarge method of IOUtil instead of copy.
     
Thanks,
Sham
Twitter: @adobe_sham

Avatar

Correct answer by
Level 3

Hello depath,

Can you attach the error.log file for the use case when the file size is larger than 1 mb ?

[EDIT] Let me suggest you an alternate approach for your usecase,

  1. Rather than sending the file binary data to the servlet, you can first upload the file to a temp path and then create an attribute in the request containing this file path which is available to the servlet.
  2. Now, in the servlet, you can use this path to access the binary contents.
  3. This approach would always work because you are never dependent on file size anywhere, the file gets uploaded first in a temporary path(using sling post servlet)[1] and then you use this path to access the file contents.

Let me know your thoughts.

Thanks

[1] http://sling.apache.org/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-pos...