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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:23:08+00:00 2026-05-26T09:23:08+00:00

I have an html-form with a field that will take a url pointing to

  • 0

I have an html-form with a field that will take a url pointing to a (possibly binary) file (e.g. an image). The url can point to a local resource that the server can’t reach, so it needs to be fetched by the client. (This fetching is another point, my question is about writing the servlet.)

I want to upload the result of this fetch to a Java servlet (through a http POST request) and put it into an array of bytes. Since this is a low-level representation, I’m not sure if I should use Apache’s FileUpload.

Another point that confused me, is that FileItems in FileUpload only provide an OutputStream where I was expecting an InputStream to read the file.

I’m stuck after studying FileUpload. I may be that my basic knowledge of web-app development falls short.

How should I build this functionality? Please note that I’m new to this corner of Java development (although my general (i.e. SE) Java skills are very good).

  • 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-26T09:23:08+00:00Added an answer on May 26, 2026 at 9:23 am

    Just keep using FileUpload, don’t reinvent it yourself. This will be a waste of time.

    I’m not sure why you think that FileItem only provides an OutputStream, there’s also an getInputStream() method. Just write it to a ByteArrayOutputStream.

    InputStream input = fileItem.getInputStream();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    IOUtils.copy(input, output);
    byte[] bytes = output.toByteArray();
    // ...
    

    You only need to keep in mind that this may explode your server’s memory usage if there are a lot of users uploading files at the same time. Each byte of a byte array eats one byte of JVM’s memory. So imagine you’ve 100 simultaneous users who upload each a 10MB file, then 1GB of server memory is wasted to this.

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

Sidebar

Related Questions

We have got an extjs 3.1.1 form with file upload field ( http://www.extjs.com/deploy/dev/examples/form/file-upload.html from
I have a field that will need to ALLOW HTML. It's 100% valid and
I'm using a HTML form's TEXTAREA field that will contain text and it may
I have a HTML form, and I have a Controller Action that accepts the
I have a html form for uploading a file, which is as follows: $uploadhtml
I have an HTML form where the user can type in any number:5, 8,
I have set up a little snippet that will take an autoresponder code for
I have 3 HTML form inputs fields that is dynamically generated by a add
For instance, I want to have a html form that looks like this: <table>
Currently I have an HTML form with a hidden field right before a text

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.