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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:19:07+00:00 2026-06-06T10:19:07+00:00

I am writing my own implementation of the Google Drive client for the Android

  • 0

I am writing my own implementation of the Google Drive client for the Android and I am using the docs list api. Recently I’ve encountered a following problem:

At first I was using the HttpURLConnection to upload the file but it seems like it writes the data to the socket after a call to getResponseCose(), not when I am writing to the connection’s OutputStream, which is a must for me.

Then I’ve switched to the Apache HttpClient but I’m still getting a 400 response, not sure why. Maybe you will be able to help me. Here is the code used to upload a file.

String putUrl = conn.getHeaderField("Location");//from the previous request
final HttpClient client = new DefaultHttpClient();
final HttpPut put = new HttpPut(putUrl);

MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
put.addHeader("Content-Type", mime==null?"file":mime);
//put.addHeader("Content-Length", String.valueOf(length));
put.addHeader("Content-Range", "bytes 0-"+(length-1)+"/"+length);
put.addHeader("GData-Version", "3.0");
put.addHeader("Authorization", getAuthorizationProperty());
entity.addPart("content", new InputStreamBody(in, name));
put.setEntity(entity);

HttpResponse resp = client.execute(put);
int response = resp.getStatusLine().getStatusCode();
if(response == HttpStatus.SC_CREATED){
    lastCreated = parseSingleXMLEntry(resp.getEntity().getContent());
}

Exactly the same headers worked for HttpURLConnection. Maybe the entity is wrong?

  • 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-06T10:19:12+00:00Added an answer on June 6, 2026 at 10:19 am

    Ok, the solution is quite simple, hope it will be useful for someone.

    I had to delete all lines which added headers to the request. After that I’ve added the mime type to the InputStreamBody constructor and overriden the getContentLength() method to provide stream length. Finally it looks like this:

    MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    entity.addPart("content", new InputStreamBody(in, ,mime, name){
         @Override
         public long getContentLength() {
              return length;
         }
    });
    put.setEntity(entity);
    
    HttpResponse resp = client.execute(put);
    

    And that’s all.

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

Sidebar

Related Questions

I've written my own generic tree implementation, and when writing iterators for it, I
I'm currently writing my own virtual keyboard for linux using the X11 lib and
I am considering writing my own implementation of reliable UDP (packet ordering and retransmission
I'm writing my own implementation of JMX console for JBoss 6.1 based on JSF.
I am in the process of writing my own gridview implementation( Based of the
I'm writing my own implementation of the C++ STL map container. Now I'm trying
I'm going to be writing my own STUN implementation in JavaScript (server-side with NodeJS),
I'm creating a doubly linked list implementation of my own for fun and I've
Basically I'm writing my own version of a 'RoleProvider' and 'AuthorizeAttribute'. I've got an
I am writing my own blog (every one should, it's good experience). I have

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.