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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:10:13+00:00 2026-06-15T00:10:13+00:00

I wanted to upload images from my sd card to the folder in a

  • 0

I wanted to upload images from my sd card to the folder in a server. I have the following informations
http://mywebsite.myworks.com/parent/webservices/myuploader.ashx (POST)

Content-Disposition: form-data; name="Filename"
FilName.jpg

Content-Disposition: form-data; name="password"
mypassword

Content-Disposition: form-data; name="action"
upload

Content-Disposition: form-data; name="parentNodeId"
1297

Content-Disposition: form-data; name="replaceExisting"
0

Content-Disposition: form-data; name="username"
admin

Content-Disposition: form-data; name="Filedata"; filename="2012-11-07 11-03-37.jpg"
Content-Type: application/octet-stream
[DATA]

Basically what i want is to upload image to the folder.What i have understood so far is to upload to the folder whose parentNodeId is 1297. I saw some tutorials on how to upload images to php server .Based on that i wrote a function. Im sharing it below

private void doFileUpload() {
    HttpURLConnection conn = null;
    DataOutputStream dos = null;
    DataInputStream inStream = null;
    String exsistingFileName = "/sdcard/r.jpg";

    // Is this the place are you doing something wrong.
    String lineEnd = "rn";
    String twoHyphens = "--";
    String boundary = "*****";

    int bytesRead, bytesAvailable, bufferSize;
    byte[] buffer;
    int maxBufferSize = 1 * 1024 * 1024;
    String responseFromServer = "";
    String urlString = "http://mywebsite.myworks.com/parent/webservices/myuploader.ashx";

    try {
        // ------------------ CLIENT REQUEST
        Log.e("UploadMe", "Inside second Method");
        FileInputStream fileInputStream = new FileInputStream(new File(exsistingFileName));

        // open a URL connection to the Servlet
        URL url = new URL(urlString);

        // Open a HTTP connection to the URL
        conn = (HttpURLConnection) url.openConnection();

        // Allow Inputs
        conn.setDoInput(true);

        // Allow Outputs
        conn.setDoOutput(true);

        // Don't use a cached copy.
        conn.setUseCaches(false);

        // Use a post method.
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Connection", "Keep-Alive");
        // conn.setRequestProperty("Content-Type",
        // "multipart/form-data;boundary="+boundary);
        conn.setRequestProperty("Content-Type", "application/octet-stream");

        dos = new DataOutputStream(conn.getOutputStream());
        dos.writeBytes(twoHyphens + boundary + lineEnd);
         dos.writeBytes("Content-Disposition: form-data; name=\"Filename\";filename=\""
         + exsistingFileName + "\"" + lineEnd);
        dos.writeBytes("Content-Disposition: form-data; name=\"Filename\";filename=\""
                + "r.jpg" + "\"" + lineEnd);
        dos.writeBytes("Content-Disposition: form-data; name=\"password\";filename=\""
                + "mypassword" + "\"" + lineEnd);
        dos.writeBytes("Content-Disposition: form-data; name=\"action\";filename=\""
                + "upload" + "\"" + lineEnd);
        dos.writeBytes("Content-Disposition: form-data; name=\"parentNodeId\";filename=\""
                + "-1" + "\"" + lineEnd);
        dos.writeBytes("Content-Disposition: form-data; name=\"replaceExisting\";filename=\""
                + "0" + "\"" + lineEnd);
        dos.writeBytes("Content-Disposition: form-data; name=\"username\";filename=\""
                + "admin" + "\"" + lineEnd);
        dos.writeBytes("Content-Disposition: form-data; name=\"Filedata\";filename=\""
                + "2012-11-07 11-03-37.jpg" + "\"" + lineEnd);

        dos.writeBytes(twoHyphens + boundary + lineEnd);

        dos.writeBytes(lineEnd);
        Log.e("UploadMe", "Headers are written");

        // create a buffer of maximum size
        bytesAvailable = fileInputStream.available();
        bufferSize = Math.min(bytesAvailable, maxBufferSize);
        buffer = new byte[bufferSize];

        // read file and write it into form...
        bytesRead = fileInputStream.read(buffer, 0, bufferSize);

        while (bytesRead > 0) {
            dos.write(buffer, 0, bufferSize);
            bytesAvailable = fileInputStream.available();
            bufferSize = Math.min(bytesAvailable, maxBufferSize);
            bytesRead = fileInputStream.read(buffer, 0, bufferSize);
        }

        // send multipart form data necesssary after file data...
        dos.writeBytes(lineEnd);
        dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

        // close streams
        Log.e("UploadMe", "File is written");
        fileInputStream.close();
        dos.flush();
        dos.close();

    }

    catch (MalformedURLException ex)

    {

        Log.e("UploadMe", "error: " + ex.getMessage(), ex);

    }

    catch (IOException ioe)

    {

        Log.e("UploadMe", "error: " + ioe.getMessage(), ioe);

    }

    // ------------------ read the SERVER RESPONSE
    try {
        inStream = new DataInputStream(conn.getInputStream());
        String str;

        while ((str = inStream.readLine()) != null) {
            Log.e("UploadMe", "Server Response" + str);
        }

        inStream.close();
    }

    catch (IOException ioex) {
        Log.e("UploadMe", "error: " + ioex.getMessage(), ioex);
    }

}

The program runs with out any crash and im getting these from my log cat output.But i couldnot see anything in my server folder.

11-22 10:26:39.546: E/UploadMe(3363): Inside second Method
11-22 10:26:39.843: E/UploadMe(3363): Headers are written
11-22 10:26:39.851: E/UploadMe(3363): File is written
11-22 10:26:40.820: E/UploadMe(3363): Server Response<?xml version="1.0"?>
11-22 10:26:40.820: E/UploadMe(3363): Server Response<MediaResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" success="false" />

Since i have no idea about uploading files to server , Is this the way to upload files?

  • 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-15T00:10:14+00:00Added an answer on June 15, 2026 at 12:10 am

    One lib was available call android-async-http-1.4.2.jar using this you can upload file with post string data also

    here is the example code

    RequestParams params = new RequestParams();
    params.put("fname", "name");// here write your parameter name and its value
    params.put("file", new File(filePath)); // Upload a File
    // params.put("profile_picture2", someInputStream); // Upload an
    // InputStream
    // params.put("profile_picture3", new ByteArrayInputStream(someBytes));
    // // Upload some bytes
    
    AsyncHttpClient client = new AsyncHttpClient();
    client.post(urlServer, params, new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(String arg0) {
            super.onSuccess(arg0);
            Log.v("from response", arg0);
        }
    });
    

    here is jar download link

    https://github.com/loopj/android-async-http/downloads

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

Sidebar

Related Questions

I have a website that has images with urls like this: http://mysite.com/image1.jpg My server
I wanted to upload a jpeg image file on the server.I have a GoAhead
I'm using plupload to upload files to my server ( http://www.plupload.com/index.php ), however I
I just wanted to know how to configure FCKEditor to upload files and images
I am concerned about the allowing people to upload images to my server. I
Hi I wanted to upload images(along with other form details) and preview them, using
I have a form with a upload photo input on it. I wanted to
Trying to use the following scripts to upload, resize & save multiple images via
I was religiously following this tutorial: http://www.icodeya.com/2012/08/grails-creating-image-gallery-feat.html on how to add an image gallery
I have a Form Where users Upload Images and enter title for them and

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.