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

  • Home
  • SEARCH
  • 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 1115539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:10:16+00:00 2026-05-17T03:10:16+00:00

hello i am new in android devlopment i want to know how to upload

  • 0

hello i am new in android devlopment
i want to know how to upload an image in android
i dont found any usefull tutorial for this
can u give me some instruction,pls,help me out.

  • 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-17T03:10:17+00:00Added an answer on May 17, 2026 at 3:10 am

    I built this lil methods for you:

    private boolean handlePicture(String filePath, String mimeType) {       
        HttpURLConnection connection = null;
        DataOutputStream outStream = null;
        DataInputStream inStream = null;
    
        String lineEnd = "\r\n";
        String twoHyphens = "--";
        String boundary = "*****";
    
        int bytesRead, bytesAvailable, bufferSize;
    
        byte[] buffer;
    
        int maxBufferSize = 1*1024*1024;
    
        String urlString = "http://www.yourwebserver.com/youruploadscript.php";
    
        try {
            FileInputStream fileInputStream = null;
            try {
                fileInputStream = new FileInputStream(new File(filePath));
            } catch(FileNotFoundException e) { }
            URL url = new URL(urlString);
            connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.setDoOutput(true);
            connection.setUseCaches(false);
    
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Connection", "Keep-Alive");
            connection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);            
    
            outStream = new DataOutputStream(connection.getOutputStream());
    
            outStream.writeBytes(addParam("someparam", "content of some param", twoHyphens, boundary, lineEnd));                
    
            outStream.writeBytes(twoHyphens + boundary + lineEnd);
            outStream.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\"; filename=\"" + filePath +"\"" + lineEnd + "Content-Type: " + mimeType + lineEnd + "Content-Transfer-Encoding: binary" + lineEnd);          
            outStream.writeBytes(lineEnd);
    
            bytesAvailable = fileInputStream.available();
            bufferSize = Math.min(bytesAvailable, maxBufferSize);
            buffer = new byte[bufferSize];
    
            bytesRead = fileInputStream.read(buffer, 0, bufferSize);
    
              while (bytesRead > 0) {
                  outStream.write(buffer, 0, bufferSize);
                bytesAvailable = fileInputStream.available();
                bufferSize = Math.min(bytesAvailable, maxBufferSize);
                bytesRead = fileInputStream.read(buffer, 0, bufferSize);
            }
    
              outStream.writeBytes(lineEnd);
              outStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
    
            fileInputStream.close();
            outStream.flush();
            outStream.close();  
        } catch (MalformedURLException e) {
            Log.e("DEBUG", "[MalformedURLException while sending a picture]");
        } catch (IOException e) {
            Log.e("DEBUG", "[IOException while sending a picture]"); 
        }
    
        try {
               inStream = new DataInputStream( connection.getInputStream() );
               String str;
    
               while (( str = inStream.readLine()) != null) {
                   if(str=="1") {
                       return true;
                   } else {
                       return false;
                   }
               }
               inStream.close();
          } catch (IOException e){
              Log.e("DEBUG", "[IOException while sending a picture and receiving the response]");
          }
        return false;
    }
    
    private String addParam(String key, String value, String twoHyphens, String boundary, String lineEnd) {
            return twoHyphens + boundary + lineEnd + "Content-Disposition: form-data; name=\"" + key + "\"" + lineEnd + lineEnd + value + lineEnd;
    }
    

    Should work so far. On your webserver you need some PHP Script which returns a “1” for a successful upload and something else for an error. I also suggest to do this in a ASyncTask, to prevent blocking the user during the uploading.
    On the webserver side you’ve got a file in the name “uploadedfile”. Hope that helps!

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

Sidebar

Related Questions

No related questions found

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.