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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:20:06+00:00 2026-05-28T04:20:06+00:00

I am trying to Upload image Capture by Camera into server. server send response

  • 0

I am trying to Upload image Capture by Camera into server. server send response code = 200 but Image is not upload into server.

Code is :

private boolean uploadData() {

    int count = this.forumThreadsB.size();
    for (int i = 0; i < count; i++)
    {
            if (isPhoto)
                message = "Uploading Shared Items " + (i + 1) + " of " + count;
            else
                message = "Uploading Shared Items " + (i + 1) + " of " + count;

            progressCount = (i * 1000)/count; 
            Hashtable<?, ?> threadD = (Hashtable<?, ?>)this.forumThreadsB.elementAt(i);

            String onlinePath = "http://xyx.com/;
            threadid = (String) threadD.get("devicethreadid");
            Hashtable<String, String> pairs = new Hashtable<String, String>();
            pairs.put("forumid",  threadD.get("lmsforumid").toString());
            pairs.put("topicid",  threadD.get("lmsthreadid").toString());
            pairs.put("clientid", LoginHelper.clientid);
            String fullfilepath = threadD.get("offlinepath").toString();
            int index = threadD.get("offlinepath").toString().lastIndexOf("/");

            String filename = fullfilepath.substring(index + 1);
            String filetype = "";

            if (filename.toLowerCase().contains(".png"))
                filetype = "image/png";
            else if (filename.toLowerCase().contains(".jpg"))
                filetype = "image/jpeg";
            else if (filename.toLowerCase().contains(".mp4"))
                filetype = "image/mp4";
            else if (filename.toLowerCase().contains(".3gp"))
                filetype = "image/3gpp";



            String boundaryMessage = getBoundaryMessage(BOUNDARY, pairs, fullfilepath, filename, filetype);
            String endBoundary = "\r\n--" + BOUNDARY + "--\r\n";

            HttpURLConnection conn = null;
            DataOutputStream dos = null;
            String lineEnd = "\r\n";
            String twoHyphens = "--";
            int bytesRead, bytesAvailable, bufferSize;
            byte[] buffer;
            int maxBufferSize = 1*1024*1024;

            try
            {
                URL url = new URL(onlinePath);
                conn = (HttpURLConnection) url.openConnection();
                conn.setDoInput(true);
                conn.setDoOutput(true);
                conn.setUseCaches(false);
                conn.setRequestMethod("POST");
                conn.setRequestProperty("Connection", "Keep-Alive");
                conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+BOUNDARY);
                dos = new DataOutputStream( conn.getOutputStream() );
                dos.write( boundaryMessage.getBytes());
                File file = new File(fullfilepath.substring(6));
                FileInputStream fileInputStream = new FileInputStream(file);
                bytesAvailable = fileInputStream.available();
                bufferSize = Math.min(bytesAvailable, maxBufferSize);
                buffer = new byte[bufferSize];
                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);
                }
                dos.write(endBoundary.getBytes());
                dos.flush();
                dos.close();
                fileInputStream.close();
                } catch (IOException ioe) {
                    Log.e("SyncUploadDownloadHelper", "Cannot upload file: " + ioe.getMessage(), ioe);
                    //return false;
                }

                // Read response
                try {
                    int responseCode = conn.getResponseCode();
                    if(responseCode == 200){

                         SQLiteForumDAO forumDAO = new SQLiteForumDAO(mcontext) ;
                            ForumThreadDTO forumThreadDTO = forumDAO.selectThread(this.threadid);
                            if(downloadPath!=null && downloadPath.equalsIgnoreCase("null") && downloadPath.equalsIgnoreCase(""))
                            forumThreadDTO.offlinefilepath = downloadPath;
                            forumDAO.updateThread(forumThreadDTO);


                    }


                } catch (IOException ioex) {
                    Log.e("SyncUploadDownloadHelper", "Upload file failed: " + ioex.getMessage(), ioex);
                    //return false;
                } catch (Exception e) {
                    Log.e("SyncUploadDownloadHelper", "Upload file failed: " + e.getMessage(), e);
                    //return false;
                }

                if (i == (this.forumThreadsB.size() - 1)){
                    this.sendStatus = "true";
                    progressCount = 1000;
                    SyncUploadDownloadHelper.this.notifyObservers("SyncUploadDownloadHelper:UploadDataFinish");
                }
                else
                    SyncUploadDownloadHelper.this.notifyObservers("SyncUploadDownloadHelper:UploadData");

                //return true;

    }

    return true;
}

Function :

private String getBoundaryMessage(String boundary, Hashtable<String, String> params, String fileField, String fileName, String fileType) {
      StringBuffer res = new StringBuffer("--").append(boundary).append("\r\n");
      Enumeration<String> keys = params.keys();
      while(keys.hasMoreElements()) {
       String key = (String)keys.nextElement();
       String value = (String)params.get(key);

       System.out.println(key + ": " + value);

       res.append("Content-Disposition: form-data; name=\"").append(key).append("\"\r\n")    
       .append("\r\n").append(value).append("\r\n").append("--").append(boundary).append("\r\n");
      }
      res.append("Content-Disposition: form-data; name=\"").append("file").append("\"; filename=\"").append(fileName).append("\"\r\n") 
      .append("Content-Type: ").append(fileType).append("\r\n\r\n");

      return res.toString();
     }

in my Application I Capture Image and Save it to Database. path of save image is use to upload image file.

  • 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-28T04:20:06+00:00Added an answer on May 28, 2026 at 4:20 am

    I using this:

    public class HttpClient extends AsyncTask<Void, Integer, Long> {
        private static final int PROGRESS_DIALOG = 0;
    
        public ProgressDialog dialog;
        public File file;
        protected Long doInBackground(Void... params) {
            for (File file : files) {
    
                foto = "/sdcard/CameraExample/" + file.getName();
                DefaultHttpClient httpclient = new DefaultHttpClient();
    
                HttpPost httppost = new HttpPost(urll);
    
    
    
                MultipartEntity mpEntity = new MultipartEntity(
                        HttpMultipartMode.BROWSER_COMPATIBLE);
    
                mpEntity.addPart("form_file", new FileBody(file, "image/jpeg"));
    
                httppost.setEntity(mpEntity);
    
                HttpResponse response;
                try {
    
                    response = httpclient.execute(httppost);
    
                    HttpEntity resEntity = response.getEntity();
    
                    if (resEntity != null) {
    
                    }
                    if (resEntity != null) {
                        resEntity.consumeContent();
                    }
                } catch (ClientProtocolException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
    
    
    
            }
            return null;
        }
    
        protected void onPostExecute(Long unused) {
            progressDialog.dismiss();
    
            ((Runnable) ctx ).run();
    
            super.onPostExecute(unused);
        }
    
        protected void onPreExecute() {
        progressDialog = new ProgressDialog(ctx);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.setMessage("Загрузка фото...");
        progressDialog.setProgress(0);
        progressDialog.setMax(count);
        progressDialog.show();
        }
    
    }
    

    This code using that library:

    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.ClientProtocolException;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.entity.mime.HttpMultipartMode;
    import org.apache.http.entity.mime.MultipartEntity;
    import org.apache.http.entity.mime.content.FileBody;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.util.EntityUtils;
    import org.apache.james.mime4j.message.Message;
    

    You can find this in Google. If you don’t find – i can send you this libraries.

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

Sidebar

Related Questions

I am trying to upload an image to server using using XMLHttpRequest but fails.
i am trying to upload a image to server from iPhone application PHP code
i am trying to upload an image from a jsp page using servlet. but
I am trying to upload an image to the server. I hava a form
I am trying to upload an image to server using iphone . I haven't
I'm trying to upload an image from android to a PHP server by using
I am trying to upload an image to a directory on a server. i'm
I am trying to upload image files to the server and it gives me
Hi I am trying to upload image file using perl cgi-application. Not sure what
I am trying to upload an image to a server along with some JSON

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.