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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:32:19+00:00 2026-06-07T06:32:19+00:00

I’m trying to do something really simple, but so far I’ve been unsuccessful in

  • 0

I’m trying to do something really simple, but so far I’ve been unsuccessful in trying various methods of making it happen. I’ve tried uploading to a URL using a simple java.io.Socket, using a java.io.HttpURLConnection, and last using a org.apache.commons.httpclient.HttpClient, but I’ve failed to make it happen each time.

I need to make a request like this:

PUT http://1.2.3.4:8080/upload?ticket_id=abcdef124567890 HTTP/1.1
Host: 1.2.3.4:8080
Content-Length: 339108
Content-Type: video/mp4

\0abc\32af ... etc.

I need to write the bytes of a file (presumably from a FileInputStream) to the main request body, containing the video bytes.

I basically have two requirements:

  1. I must upload the file using a PUT request to a given server.
  2. I must be able to watch the progress of the upload as it’s happening.

How can I make this happen in Java?


EDIT

Here’s my attempt at doing this using Apache’s HttpClient:

HttpClient httpClient = new HttpClient();
PutMethod httpMethod = new PutMethod(ticket.getEndpoint());
httpMethod.setRequestHeader("Content-Type", "video/mp4");
httpMethod.setRequestHeader("Content-Length", String.valueOf(getStreamFile().length()));

final FileInputStream streamFileInputStream = new FileInputStream(getStreamFile());
final BufferedInputStream bufferedInputStream = new BufferedInputStream(streamFileInputStream);

httpMethod.setRequestEntity(new RequestEntity() {
    @Override public void writeRequest(OutputStream out) 
            throws IOException {
        byte[] fileBuffer = new byte[getBufferLength()];
        
        int bytesRead = 0;
        int totalBytesRead = 0;
        final int totalFileBytes = (int)getStreamFile().length();
        
        while ((bytesRead = bufferedInputStream.read(fileBuffer)) > 0) {
            out.write(fileBuffer, 0, bytesRead);
            totalBytesRead += bytesRead;
            
            notifyListenersOnProgress((double)totalBytesRead / (double)totalFileBytes);
        }
    }
    
    @Override public boolean isRepeatable() {
        return true;
    }
    
    @Override public String getContentType() {
        return "video/mp4";
    }
    
    @Override public long getContentLength() {
        return getStreamFile().length();
    }
});

final int responseCode = httpClient.executeMethod(httpMethod);

logger.debug("Server Response {}: {}", responseCode, 
        httpMethod.getResponseBodyAsString());

This fails with a java.net.SocketException: Broken pipe exception.

  • 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-07T06:32:21+00:00Added an answer on June 7, 2026 at 6:32 am

    For 1 you will need to use multipart request. The referred post describes it. For 2, use some counting stream wrapper as you send data. Counting stream may need to be hooked inside HttpClient.

    More details can be provided if you add more specifics on what is not working for you.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm making a simple page using Google Maps API 3. My first. One marker
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:

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.