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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:55:59+00:00 2026-06-07T23:55:59+00:00

I have an application that uploads photos through a web service. In the past,

  • 0

I have an application that uploads photos through a web service. In the past, I loaded a file into a stream, and converted to Base64. Then I posted the resulting string through the write() method of an OutputStreamWriter. Now, the web service has changed, and it expects multipart/form-data and it does not expect Base64.

So somehow I need to post the chararters of this file as is without conversion. I’m sure I’m close, but all I ever get is a content lengh underflow or overflow. The odd thing is that in the debugger I can see that my buffer length is the same length as the string I’m posting. Here’s what I’m doing and hopefully enough code:

// conn is my connection
OutputStreamWriter dataStream = new OutputStreamWriter(conn.getOutputStream());

// c is my file
int bytesRead = 0;
long bytesAvailable = c.length();

while (bytesAvailable > 0) {
   byte[] buffer = new byte[Math.min(12288, (int)bytesAvailable)];
   bytesRead = fileInputStream.read(buffer, 0, Math.min(12288, (int)bytesAvailable));

   // assign the string if needed.
   if (bytesRead > 0) {
      bytesAvailable = fileInputStream.available();

      // I've tried many encoding types here.
      String sTmp = new String(buffer, "ISO-8859-1");
      // HERE'S the issue.  I can't just write the buffer,
      dataStream.write(sTmp);
      dataStream.flush();
// Yes there's more code, but this should be enough to show why I don't know what I'm doing!
  • 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-07T23:56:00+00:00Added an answer on June 7, 2026 at 11:56 pm

    change

    OutputStreamWriter dataStream = new OutputStreamWriter(conn.getOutputStream());
    

    with this

    DataOutputStream dataStream = new DataOutputStream(conn.getOutputStream()); 
    

    and directly call dataStream.write(buffer);

    let me know how it behave

    Edit: edited answer according to comment

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

Sidebar

Related Questions

I have a Rails application that accepts file uploads of CSV files. When developing
I have an application which uploads file from iPhone to web server. Problem is
I have made an application which uploads a bunch of photos to a web
I'm building a Rails application that deals with file uploads through CarrierWave. Currently, larger
I have a Silverlight application that uploads files in chunks to a WCF service.
We have a web application that allows users to upload photos which will then
I have a legacy VB6 application that uploads file attachments to a database BLOB
I have a JavaScript application that works like this: Uploads a file, receives the
I have an iPhone application that uploads images directly to S3. Then it hits
I have a desktop application that needs to upload/download images to/from service computer over

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.