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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:43:25+00:00 2026-05-31T01:43:25+00:00

I have created http service on android. And now I want to upload the

  • 0

I have created http service on android. And now I want to upload the file from browser to server (android). Let’s look what I’ve done:

private static final String ALL_PATTERN = "*";
private static final String UPLOADFILE_PATTERN = "/UploadFile/*";
/* Some variables */
public WebServer(Context context) {
    this.setContext(context);
    httpproc = new BasicHttpProcessor();
    httpContext = new BasicHttpContext();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());
    httpService = new HttpService(httpproc,
        new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    registry = new HttpRequestHandlerRegistry();
    registry.register(ALL_PATTERN, new HomeCommandHandler(context));        
    registry.register(UPLOADFILE_PATTERN, new UploadCommandHandler(context));       
    httpService.setHandlerResolver(registry);
}

Then I write url in browser (for example http://127.0.0.1:6789/home.html (I play with emulator)). Http service sends me form like below:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>File Upload</title>
</head>
<body>
<form method="POST" action="UploadFile/" enctype="multipart/form-data">
<p>File1 Test:
<input type="file" name="myfile1" size="20">
<input type="submit" value="Upload file">
<input type="reset" value="Reset" name="someName">  
</form>
</body>

I choose some file and press submit. After that the server invoke this method:

 @Override
public void handle(HttpRequest request, HttpResponse response,
    HttpContext httpContext) throws HttpException, IOException {

    Log.e("","INSIDE UPLOADER");
    Log.e("Method",request.getRequestLine().getMethod());
    Log.e("len",request.getRequestLine()+"");
    for(Header h : request.getAllHeaders()){
        Log.e("len", h.getName()+" = "+h.getValue()); 
    }
}

It returns in LogCat:

Content-Length = 4165941
Content-Type = multipart/form-data; boundary=----WebKitFormBoundarykvmpGbpMd6NM1Lbk
Method POST /UploadFile/ HTTP/1.1

and other parameters.
My question is where can I get the file content? I mean some InputStream or something else. I know HttpResponse has method like getContent(). But HttpRequest has no this one.
Thanks.

  • 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-31T01:43:26+00:00Added an answer on May 31, 2026 at 1:43 am

    If the HttpRequest contains an entity it should also implement HttpEntityEnclosingRequest. This goes in your #handle(HttpRequest request, HttpResponse response) method:

    if (request instanceof HttpEntityEnclosingRequest) {
        HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request;
        HttpEntity entity = entityRequest.getEntity();
        if (entity != null) {
            // Now you can call entity.getContent() and do your thing
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a little example,please have a look, http://jsfiddle.net/bWTwL/ I want to have
I have a RESTful web service and I want to access it from Android.
i have created a Java Restful Web service . Now i want to access
I have installed SQLite and am using the wrapper from: http://sqlite.phxsoftware.com/ I have created
I was already running a sub-website under following path http://example.com/sub-site/ Now, I have created
I am new to Android . I have created a web service in Visual
I'm trying to upload a file from Android (2.3.4) using the below code, I
I am using ASP MVC 2 and Nhibernate. I have created an HTTP Module
I have created the following demo: http://thedrivepartnership.com/overflow.html The scrolls expand fine in FireFox /
I have created a fiddle to test this : http://jsfiddle.net/Ninjanoel/X6ShS/ which works fine :(

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.