0

im using multipart entity to upload to my image to server.this is my code

private void uploadFile() {
             try {
            HttpClient httpclient = new DefaultHttpClient();
             httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
             HttpPost httppost = new HttpPost(rest_url);

             Map<String, Object> data = new LinkedHashMap<String, Object>();
                data.put(SESSION, sessionId);
                data.put(MODULE_NAME, "POD_POD");

                String restData = org.json.simple.JSONValue.toJSONString(data);


             File file = new File(signature_path);
             MultipartEntity mpEntity = new MultipartEntity();
             ContentBody cbFile = new FileBody(file, "image/jpeg");
            // mpEntity.addPart("userfile", cbFile); 

             mpEntity.addPart(METHOD, new StringBody(SET_ENTRY));
             mpEntity.addPart(INPUT_TYPE, new StringBody(JSON));
             mpEntity.addPart(RESPONSE_TYPE, new StringBody(JSON));
             mpEntity.addPart(REST_DATA, new StringBody(restData));

                mpEntity.addPart("name",
                         new StringBody("uploadfile"));

             // Adding file data to http body
             mpEntity.addPart("value", cbFile);

             httppost.setEntity(mpEntity);
             System.out.println("executing request " + httppost.getRequestLine());

             HttpResponse response;


                response = httpclient.execute(httppost);

            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

This is Logcat

FATAL EXCEPTION: main
Process: com.stonewheeltest, PID: 18823
java.lang.NoClassDefFoundError: org.apache.http.entity.ContentType
at org.apache.http.entity.mime.content.FileBody.<init>(FileBody.java:85)
at newCrm.Sugercrm_sync.uploadFile(Sugercrm_sync.java:207)
at newCrm.Sugercrm_sync.access$0(Sugercrm_sync.java:192)
at newCrm.Sugercrm_sync$AddNewRecord.onPostExecute(Sugercrm_sync.java:185)
at newCrm.Sugercrm_sync$AddNewRecord.onPostExecute(Sugercrm_sync.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)

Anyone can help me..

1

1 Answer 1

3

I had a similar problem, for me adding the following dependencies solved the problem:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:20.+'
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
    compile('org.apache.httpcomponents:httpmime:4.3') {
        exclude module: "httpclient"
    }

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.