Created
June 7, 2013 07:54
-
-
Save shailja-thakur/5727680 to your computer and use it in GitHub Desktop.
file upload android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.sensormanagement; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.InputStreamReader; | |
import org.apache.http.HttpEntity; | |
import org.apache.http.HttpResponse; | |
import org.apache.http.client.HttpClient; | |
import org.apache.http.client.methods.HttpPost; | |
import org.apache.http.entity.FileEntity; | |
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.params.BasicHttpParams; | |
import org.apache.http.params.HttpConnectionParams; | |
import org.apache.http.params.HttpParams; | |
import org.apache.http.util.EntityUtils; | |
import android.util.Log; | |
public class Fileuploader { | |
public static String ContactMUC( String FilePath , int USER_ID , String CONN_URL, String Key ) | |
{ | |
HttpParams httpParameters = new BasicHttpParams(); | |
HttpConnectionParams.setConnectionTimeout(httpParameters, 5000000); | |
HttpConnectionParams.setSoTimeout(httpParameters, 100000000); | |
HttpClient httpclient = new DefaultHttpClient(); | |
HttpPost httppost = new HttpPost(CONN_URL); | |
MultipartEntity reqEntity = new MultipartEntity(); | |
FileBody bin = new FileBody( new File(FilePath)); | |
reqEntity.addPart(Key, bin); | |
httppost.setEntity(reqEntity); | |
httppost.setEntity(reqEntity); | |
HttpResponse response = null; | |
String Data = ""; | |
try | |
{System.out.println("hello"); | |
response = httpclient.execute(httppost); | |
System.out.println("hello1"); | |
BufferedReader BuffRead = new BufferedReader( new InputStreamReader(response.getEntity().getContent(),"UTF-8") ); | |
Data = BuffRead.readLine(); | |
Log.i("testing",response.getStatusLine().toString()); | |
Log.i("testing",Key+Data); | |
} | |
catch(Exception error){ return null; } | |
if(response.getStatusLine().toString().equalsIgnoreCase("HTTP/1.1 200 OK")){ | |
return Data; | |
} | |
else | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment