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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:13:54+00:00 2026-05-25T10:13:54+00:00

I need to upload an image file and generate a thumbnail for the uploaded

  • 0

I need to upload an image file and generate a thumbnail for the uploaded file in my JSF webapplication. The original image is stored on the server in /home/myname/tomcat/webapps/uploads, while the thumbnail is stored in /home/myname/tomcat/webapps/uploads/thumbs. I’m using the thumbnail generator class I copied from philreeve.com.

I have successfully uploaded the file with help from BalusC. But using Toolkit.getImage(), I can’t access the image.

I used the uploaded file’s absolute path, like so:

inFilename = file.getAbsolutePath();

The relevant code from the thumbnail generator is:

public static String createThumbnail(String inFilename, String outFilename, int largestDimension) {
    ...
    Image inImage = Toolkit.getDefaultToolkit().getImage(inFilename);
    if (inImage.getWidth(null) == -1 || inImage.getHeight(null) == -1) {
        return "Error loading file: \"" + new File(inFilename).getAbsolutePath() + "\"";
    }
    ...
}

Since I am already using the absolute path, I don’t understand why it is not working. I have also used the following values for inFilename, but I always get the “Error loading file…”.

  • /home/myname/tomcat/webapps/uploads/filename.ext
  • /uploads/filename.ext

But I did check the directory, and the image is there. (I uploaded using /home/myname/tomcat/webapps/uploads/filename.ext, and it works.) What is the correct path for the image in that directory? Thank you.

Update

I got the code to work by using:

Image inImage = ImageIO.read(new File(inFilename));

I still don’t understand why Toolkit.getImage() does not work though.

  • 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-05-25T10:13:54+00:00Added an answer on May 25, 2026 at 10:13 am

    Are you sure it’s a JPEG file? Use an image viewer to make sure nothing bad happened to the file during upload (or that it was an image to begin with).

    Also, use new File(inFilename).exists() to make sure the path is correct. I also suggest to print new File(inFilename).getAbsolutePath() in error messages because relative paths can hurt you.

    That said, the rest of the code looks correct.

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

Sidebar

Related Questions

I need to upload image to the server, where SmartGWT webapplication is running... after
How to upload a image file using ajax by using prototype.js plugin, I need
I need to upload an image to a remote PHP server which expects the
I'm hosting a web site at localhost and need to upload image file to
I use this code to upload image files in xammp server: <?php if ((($_FILES[file][type]
How can I upload an image file to a webservice using SOAP? I need
I need a method which will take an *.jpg image file and upload it
I need to generate name of uploaded image with mask images/{{ uploaded_image.id }}.jpg I
I need to upload only image file through <input type="file"> tag. Right now, it
I need to upload an image as part of a create action in an

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.