Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String uploadFile(){
- if (DEBUG)Log.d(TAG, "onActivityResult: data==null");
- try {
- Uri outputFileUri = Uri.fromFile(file);
- if(DEBUG)Log.d(TAG,"outputFileUri post: "+outputFileUri);
- HttpClient imgClient = new DefaultHttpClient();
- imgClient.getParams().setParameter("http.connection.timeout",Integer.valueOf(1000));
- if(DEBUG)Log.d(TAG,"Service Image Upload: "+url);
- HttpPost imagePost = new HttpPost(url);
- BasicHttpEntity imgEntity = new BasicHttpEntity();
- imgEntity.setContent(new FileInputStream(file));
- imagePost.setEntity(imgEntity);
- imagePost.setHeader("imageName", "image");
- imagePost.setHeader("imageExtension", "jpg");
- HttpResponse imgResponse = imgClient.execute(imagePost);
- if (imgResponse.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK) {
- HttpEntity httpEntity = imgResponse.getEntity();
- String response = EntityUtils.toString(httpEntity,HTTP.UTF_8);
- if (DEBUG)Log.d(TAG,"imgUpload response:"+response );
- return response;
- }else{
- if (DEBUG)Log.d(TAG,"imgUpload response: FAIL");
- return null;
- }
- } catch (ClientProtocolException e) {
- if (DEBUG)Log.d(TAG, "ClientProtocolException:");
- e.printStackTrace();
- return null;
- } catch (IOException e) {
- if (DEBUG)Log.d(TAG, "IOException:");
- e.printStackTrace();
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment