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 8009415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:26:35+00:00 2026-06-04T18:26:35+00:00

SUMMARY I need to store both uploaded and server-generated images, with portable and predictable

  • 0

SUMMARY

  1. I need to store both uploaded and server-generated images, with portable and
    predictable paths so my server code is aware of where these images exist.
  2. I need to generate URLs to these images that can be sent to the client. These URLs will be used in HTML image elements.

PROBLEM

My web application allows the user to upload an image, using gwtupload(Apache Commons). This image is stored on the server and a URL returned to the client so the image is shown. gwtupload provides a clientside method to get this URL for the uploaded image. This works in deployment; the following aspects do not:

  • In certain cases, the uploaded image must be cropped. This results in
    a new image being generated by a servlet method. I want to store this
    cropped image and return(to the client) an access URL.
  • Then, this image is used by another method to generate another
    image. This method must know the location on the file system of
    the previously uploaded(and/or cropped) image. A URL for the new
    image must then be returned to client.

I have implementation working perfectly in GWT development mode. However, as I expected, after deployment to my own Tomcat server, the remote services fail due to my confusion regarding the file system. I do not know the correct way of storing these images in a predictable place on the server filesystem, nor do I know how to generate access URLs(for files residing outwith the WAR, as these images will.)

All these images are only needed for the current session, so the locations can be temporary directories. I have spent two days experimenting and trawling the web for a solution to no avail.

I will post abridged code below. This is my attempt to simply use the working directory and relative pathnames. Using the Eclipse debugger attached to my servlet container, I could see the results of String dataDir = context.getRealPath(“foo”) indicating a temp folder within the servlet: but when I navigated there using explorer, NONE of the files had been written to the disk. I am very confused.

public String[] generatePreview(String xml) {

    PreviewManager manager = new PreviewManager();
    String url;

    try{       
        preview = manager.generatePreview(xml);
    }
    catch (Exception e){e.printStackTrace();}

    //Create the preview directory
    File folder = new File("previews");
    if (!folder.exists()) folder.mkdir();

    //The file to be written to
    File output = new File(folder, "front.jpg");

    ServletContext context = getServletContext();
    String dataDir = context.getRealPath("previews");

    try {
         ImageIO.write(image, "jpg", output);
    } catch (IOException e) {
         e.printStackTrace();
    }

    url = "previews/" + output.getName();

    return url;
}

@Override
public String cropBackground(int[] coord_pair, String relativePath) {

    File backgroundsFolder = new File("backgrounds");
    if (!backgroundsFolder.exists()) backgroundsFolder.mkdir();

    ServletContext context = getServletContext();
    String dataDir = context.getRealPath("backgrounds");

    File current = new File(relativePath);
    String croppedName = "cropped_" + relativePath.replace("./backgrounds/", "");

    int x = coord_pair[0];
    int y = coord_pair[1];
    int width = coord_pair[2];
    int height = coord_pair[3];
    String croppedPath = null;

    try {
        croppedPath = imageCropper.createCroppedImage(current, "backgrounds",      croppedName, x, y, width, height);
    }
    catch (IOException e){
        e.printStackTrace();
    }

    current.delete();
    return "backgrounds/" + croppedPath;

I am aware that my current ‘return’ statements would never work in deployment: I need to generate the URLs properly and return as strings. I’m sorry about the question length but I wanted to make my problem clear.

  • 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-04T18:26:38+00:00Added an answer on June 4, 2026 at 6:26 pm

    Choose a directory where your images will be stored, outside of Tomcat. Assign some unique ID to each uploaded or generated image, and store the images in this directory (with the ID as file name, for example).

    Generate URLs to an image servlet that will read the image by ID in this directory, and send the bytes of the image to the output stream of the servlet response : image.action?id=theImageId.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Executive summary: I need a way to determine whether a Windows process I've spawned
(Summary: My users need to be able to edit the structure of their dynamically
Summary: 1. Need to open a new window to display a survey from a
Summary: We need to duplicate the behaviour of the Add Reference dialog, using DTE,
Summary : I need to authorize pages based upon the data present in the
Summary I am after some advice on the easiest way to analyze simple data
Summary: I'm trying to write a text string to a column of type varchar(max)
Summary: How should the UIViewController know the size of its UIView instance when initialising
Summary of my question: Does NSURLConnection retain its delegate? Detailed question and scenario: I
SUMMARY How can I make my GUI application run on windows startup on 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.