Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7935631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:58:58+00:00 2026-06-03T21:58:58+00:00

After many hours spent on reading documentations and searching for some tips on the

  • 0

After many hours spent on reading documentations and searching for some tips on the internet, I finally decided to create a Stack OverFlow account; seem desperate? Haha, let’s go.

EDIT (05/16/2012) : As I found the solution (by myself, finally), I replaced my old code with my running code.

I go to /admin/lstimg (ListImage), which gets an image (URL) records collection, from my database. Then the collection is set as an attribute which allows me to use the data in my jsp file.

Note : The public class ListImageServlet extends HttpServlet and is annotated with MultipartConfig.

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException
    {
        try
        {
            Collection images = ImageFacade.getIjc().findImageEntities();
            request.setAttribute("images", images);
            request.getRequestDispatcher("/adm/img/lstimg.jsp").forward(request, response);
        }

        catch (Exception ex)
        {
            Logger.getLogger(ListImageServlet.class.getName()).log(Level.SEVERE, "Cannot retrieve the images.", ex);
        }
    }

In my jsp, there’s a large form (as my “images” collection is). Here, I use the data from the “images” collection. For each image, in the first column, a thumbnail and in the second column, a file input. I’m trying to perform multiple updates through this (single) form.

<form method="post" action="../admin/lstimg" enctype="multipart/form-data">
<table>
    <thead>
        <tr>
            <th>Thumb</th>
            <th>to update</th>
        </tr>
    </thead>
    <tbody>
        <c:forEach items="${images}" var="image">
            <tr>
                <td>
                    <img src="myURL" height="100"/>
                </td>
                <td>
                    <input type="file" name="${image.thumb}"/>
                </td>
            </tr>
        </c:forEach>
    </tbody>
</table>
<input type="submit" value="Proceed" />
</form>

My first question is :
As I need the new image to have the same “image.thumb” (which is the Key), I set the file input name to the current “image.thumb” but I was wondering if, I’ll have some issues to retrieve my file on my computer? As my file on my computer has its own path/filename and the one on my server has another path/UUID (Key).

EDIT (05/16/2012) : As the AWS doesn’t ask for the file path (to be manually set), no issue with this.

How the form looks (Web Browser)

After I choosed the image(s) I need to update/change, I click on the Submit button (Proceed).

  1. I get all the Parts (file inputs) and store them in a collection “allParts”.
  2. I check every part of the “allParts” collection, if the file size is between 1b and 10Mo, the part is added to the “selectedParts” collection.
  3. Here, I don’t know how to do what I want to do… All my images are hosted in my Amazon S3 Server. I use the Jets3t Toolkit. For the first upload, I call the buildPostForm method (below) and it does everything.
S3Service.buildPostForm(String bucketName, String key, ProviderCredentials credentials, Date expiration, String[] conditions, String[] inputFields, String textInput, boolean isSecureHttp);

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        try
        {
            ImageCheck.initAS3(request);
            ImageCheck.update(request, response);
        } 

        catch (S3ServiceException ex) 
        {
            Logger.getLogger(ListImageServlet.class.getName()).log(Level.SEVERE, null, ex);
        } 

        catch (ServiceException ex) 
        {
            Logger.getLogger(ListImageServlet.class.getName()).log(Level.SEVERE, null, ex);
        } 

        catch (NoSuchAlgorithmException ex) 
        {
            Logger.getLogger(ListImageServlet.class.getName()).log(Level.SEVERE, null, ex);
        } 

        catch (IllegalStateException ex) 
        {
            Logger.getLogger(ListImageServlet.class.getName()).log(Level.SEVERE, null, ex);
        }

        response.sendRedirect("../admin/lstimg");
    }

My second question is :
To upload/change a file through the servlet, as I use my own form, I need to set the File to my S3Object, but I don’t know what I can do with my “selectedParts”? Is there a way to change a Part to a File? Do I have to use something else than Part?

EDIT (05/16/2012) : My solution

Sorry for my english.
Thanks by advance for your suggestions, advices, answers.
If you have any question regarding the code or if you need some more, don’t hesitate.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:58:59+00:00Added an answer on June 3, 2026 at 9:58 pm

    I was so focused on S3Object#S3Object(java.io.File) that I didn’t realized I could use StorageObject#setDataInputStream.

    As I set the old image Key to the new image Key, my new problem is the web browser which keeps in cache the old image. I spent a lot of time on this, thinking my function wasn’t running correctly, even if I didn’t even know where I could have made a mistake; but I went on my AWS and checked the ‘Last Modified’ value that had been successfully updated. I cleared my cache and I figured out everything was ok from the very beginning.

    If it can help some, I provide the functions I did which permit to change several S3Object through a single form. If you have any questions, suggestions or if you need any comment on that code, I’m here.

    public static void upload(HttpServletRequest request, Part part, S3Service s3Service, S3Bucket s3Bucket) 
            throws S3ServiceException, NoSuchAlgorithmException, IOException
    {
        S3Object s3Object = new S3Object();
        s3Object.setDataInputStream(part.getInputStream());
        s3Object.setKey(part.getName());
        s3Object.setContentLength(part.getSize());
        s3Object.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
        s3Service.putObject(s3Bucket, s3Object);
    }
    
            public static void update(HttpServletRequest request) 
            throws S3ServiceException, ServiceException, NoSuchAlgorithmException, IOException, IllegalStateException, ServletException
    {
        AWSCredentials awsCredentials = (AWSCredentials) request.getSession().getAttribute("awsCredentials");
        S3Service s3Service = (S3Service) request.getSession().getAttribute("s3Service");
        S3Bucket s3Bucket = (S3Bucket) request.getSession().getAttribute("s3Bucket");
        String bucketName = (String) request.getSession().getAttribute("bucketName");
    
        String prefix = "uploads/";
        String delimiter = null;
        S3Object[] filteredObjects = s3Service.listObjects(bucketName, prefix, delimiter);
    
        Collection<Part> allParts = request.getParts();
        Collection<Part> selectedParts = new ArrayList<Part>();
        Collection<String> keys = new ArrayList<String>();
    
        for (Part part : allParts)
        {
            if (part.getSize()>1 && part.getSize()<10485760)
            {
                selectedParts.add(part);
            }
        }
    
        for (int o = 0; o < filteredObjects.length; o++)
        {
            String keyObject = filteredObjects[o].getName();
            keys.add(keyObject);
        }
    
        if (selectedParts.size() > 0)
        {
            for (Part part : selectedParts)
            {
                if (keys.contains(part.getName()))
                {
                    s3Service.deleteObject(s3Bucket, part.getName());
                    upload(request, part, s3Service, s3Bucket);
                }
    
                else
                {
                    selectedParts.remove(part);
                }
            }
        }
    
        else
        {
            String ex = "No file to update.";
            exceptions.add(ex);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After many hours of searching and reading articles I am not able to call
After many hours of debugging and analysis, I have finally managed to isolate the
After googling for many hours for a solution for the above Sharepoint exception, I
After many hair-pulling frustrations I've finally got one version of the PerlMagick module working
After reading many of the replies to this thread , I see that many
After one week searching and converting many algorithm from other language into php to
After many hours of hair pulling, I look to stackoverflow to help me solve
I have spent many hours looking for a solution to this and need help.
Trying to parse an nested expressions like GroupParser.parse({{a}{{c}{d}}}) After many hours i have now
I have spent many hours looking into this and I still can't find a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.