2016-08-22 3 views
0
내 응용 프로그램에서 프로필 사진 업로드를 구현해야

REST :사진은 발리로 업로드하고 API

어떻게 내가 내 서버의 폴더 (/ 업로드)에있는 갤러리에서 사진을 업로드 할 수 있습니까? 내 나머지 API와 Volley를 사용하여이 작업을 수행 할 수 있습니까?

public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if (requestCode == GALLERY && resultCode != 0) { 
     Uri mImageUri = data.getData(); 
     Log.d("TAG", mImageUri.toString()); 
     try { 
      Image = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), mImageUri); 
      if (getOrientation(getActivity().getApplicationContext(), mImageUri) != 0) { 
       Matrix matrix = new Matrix(); 
       matrix.postRotate(getOrientation(getActivity().getApplicationContext(), mImageUri)); 
       if (rotateImage != null) 
        rotateImage.recycle(); 
       rotateImage = Bitmap.createBitmap(Image, 0, 0, Image.getWidth(), Image.getHeight(), matrix,true); 
       bm = rotateImage; 
       iv.setImageBitmap(rotateImage); 
      } else{ 
       bm = Image; 
       iv.setImageBitmap(Image); 
      } 
     } catch (FileNotFoundException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
} 

이것은 사용자가 프로필 사진을 클릭 할 때 imageview를 설정하는 방법이지만 맨 위로 업로드/검색해야합니다.

+0

확인이 답변 : http://stackoverflow.com/a/30616268/1281775 – Seishin

+0

당신은 FTP 업로드를 찾고 계십니까? –

+0

내 라이브러리 사용해보기 https://github.com/amitshekhariitbhu/Fast-Android-Networking –

답변

0

이 시도 .....

public static JSONObject postFile(String url,String filePath,int id){ 

String result=""; 
HttpClient httpClient = new DefaultHttpClient(); 
HttpPost httpPost = new HttpPost(url); 
File file = new File(filePath); 
MultipartEntity mpEntity = new MultipartEntity(); 
ContentBody cbFile = new FileBody(file, "image/jpeg"); 
StringBody stringBody= null; 
JSONObject responseObject=null; 

try { 

    stringBody = new StringBody(id+""); 
    mpEntity.addPart("file", cbFile); 
    mpEntity.addPart("id",stringBody); 
    httpPost.setEntity(mpEntity); 
    System.out.println("executing request " + httpPost.getRequestLine()); 
    HttpResponse response = httpClient.execute(httpPost); 
    HttpEntity resEntity = response.getEntity(); 
    result=resEntity.toString(); 
    responseObject=new JSONObject(result); 
} 
catch (UnsupportedEncodingException e) { 
    e.printStackTrace(); 
} 
catch (ClientProtocolException e) { 
    e.printStackTrace(); 
} 
catch (IOException e) { 
    e.printStackTrace(); 
} 
catch (JSONException e) { 
    e.printStackTrace(); 
} 
    return responseObject; 
} 
+0

내가 지정해야하는 URL은 무엇입니까? 내 서버의/uploads 폴더에 업로드 할 내 API를 타겟팅해야합니까? 또는 내/폴더에 직접 업로드 할 수 있습니까? –

+0

서버의 URL은 http : //........com/ulpoad입니다. 이전에 서버에 생성 한 폴더입니다. –

관련 문제