Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

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

Avatar

Avatar
Validate 1
Level 1
depath
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
depath
Level 1

Likes

0 likes

Total Posts

7 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
depath
Level 1

15-10-2015

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 1
Level 2
rishim22446870
Level 2

Likes

2 likes

Total Posts

32 posts

Correct Reply

12 solutions
Top badges earned
Boost 1
Affirm 5
Affirm 3
Affirm 10
Affirm 1
View profile

Avatar
Boost 1
Level 2
rishim22446870
Level 2

Likes

2 likes

Total Posts

32 posts

Correct Reply

12 solutions
Top badges earned
Boost 1
Affirm 5
Affirm 3
Affirm 10
Affirm 1
View profile
rishim22446870
Level 2

15-10-2015

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...

Answers (1)

Answers (1)

Avatar

Avatar
Boost 50
Level 10
Sham_HC
Level 10

Likes

160 likes

Total Posts

2,114 posts

Correct Reply

1,204 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 25
Boost 100
View profile

Avatar
Boost 50
Level 10
Sham_HC
Level 10

Likes

160 likes

Total Posts

2,114 posts

Correct Reply

1,204 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 25
Boost 100
View profile
Sham_HC
Level 10

15-10-2015

Hi depath,

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