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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:25:00+00:00 2026-06-06T03:25:00+00:00

am I uploading this file right? Here is my code: Deleted Code it is

  • 0

am I uploading this file right? Here is my code:


Deleted Code

it is basically just a async task that sends the file (csv) to the web server.

I am getting back status code 400 🙁 Anyone know what I am doing wrong?


Edit: Now I am getting back status code 411, but when I specify the content-length it comes back with ClientProtocolException.

Here’s my code now:

UploadTask uploadtask;

    public class UploadTask extends AsyncTask<Void, byte[], Boolean> {

        HttpPost httppost;

        @Override
        protected Boolean doInBackground(Void... params) {
            Boolean result = false;
            String id = projectIDs.get((int) spinner.getSelectedItemId());

            Log.i("TAG", id);
            try {

                l(send(String.valueOf(id), "http://" + site
                        + "/restlet/position.csv?project=" + id,
                        "/csv.csv"));

            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return result;
        }

        private void entity(String id, String file) throws JSONException,
                UnsupportedEncodingException, FileNotFoundException {
            // Add your data
            File myFile = new File(Environment.getExternalStorageDirectory(),
                    file);

            FileEntity fileEntity = new FileEntity(myFile, "multipart/form-data;");
            fileEntity.setChunked(true);
            long len = fileEntity.getContentLength();
            httppost.getParams().setParameter("project", id);
            httppost.setEntity(fileEntity);

            //httppost.addHeader("Content-Length",String.valueOf(len));
            httppost.setHeader("Content-Length", String.valueOf(len));
        }

        private String send(String id, String URL, String file)
                throws ClientProtocolException, IOException, JSONException {

            l(URL);

            HttpResponse response = null;

            httppost = new HttpPost(URL);

            entity(id, file);

            response = httpclient.execute(httppost);

            Header[] head = response.getAllHeaders();

            String str = String.valueOf(response.getStatusLine()
                    .getStatusCode());

            response.getEntity().consumeContent();

            return str;
        }

    }
  • 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-06T03:25:03+00:00Added an answer on June 6, 2026 at 3:25 am

    This code here worked for uploading a file to the web server 🙂 After many hours of struggle I got it, had to import MultipartEntity, StringBody and FileBody from apache however

    httppost = new HttpPost(URL);
    MultipartEntity entity = new MultipartEntity();
    entity.addPart("title", new StringBody("position.csv", Charset.forName("UTF-8")));
    File myFile = new File(Environment.getExternalStorageDirectory(), file);
    FileBody fileBody = new FileBody(myFile);
    entity.addPart("file", fileBody);
    httppost.setEntity(entity);
    httppost.getParams().setParameter("project", id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this file that I am uploading to the server via php file
I have this code below and the problem is that it is not uploading
I am uploading file(pdf for now) like this: (It is uploading content of file
I'm Getting this error in my development log while uploadify is uploading the file
I want to get this image uploading script right, but for whatever reason it
I am trying to create an app that sends a video file to a
Hey I am trying to make a notification for my file uploading notification. This
When uploading an excel file I am receiving this error, can anyone help me?
I am working on a web application which supports file uploading. I am already
I'm new to PHP so this is probably a super trivial task: Right now

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.