2017-03-14 7 views
3

기본적으로 내가하고 싶은 것은 갤러리에서 이미지를 선택한 다음 동일한 이미지를 내 Cloudin 계정으로 업로드하는 것입니다. Cloudinary의 문서를 본 적이 있지만 작동 방식을 이해하지 못하는 이유는 무엇인지 모릅니다. 그것을 내 코드에서 구현할 수 있습니다.android에서 Cloudinary로 이미지를 업로드하는 방법은 무엇입니까?

upload_image.class ... 여기

가 나는 경우 다른 사람의 정보가 필요 가지고 링크 ... https://github.com/cloudinary/cloudinary_java/tree/master/cloudinary-android

입니다 그리고 이것은 내가 지금까지 무엇을 가지고

public class edit_profile_activity extends AppCompatActivity 
{ 
    private static int RESULT_LOAD_IMG = 1; 
    String imgDecodableString; 

    public void loadImagefromGallery(View view) 
    { 

     Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
     startActivityForResult(galleryIntent, RESULT_LOAD_IMG); 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    { 
     super.onActivityResult(requestCode, resultCode, data); 
     try 
     { 
      if (requestCode == RESULT_LOAD_IMG && resultCode == RESULT_OK && null != data) 
      { 
       Uri selectedImage = data.getData(); 
       String[] filePathColumn = { MediaStore.Images.Media.DATA }; 

       Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null); 
       cursor.moveToFirst(); 

       int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
       imgDecodableString = cursor.getString(columnIndex); 
       cursor.close(); 

       ImageView imgView = (ImageView) findViewById(R.id.circleImageView); 
       imgView.setImageBitmap(BitmapFactory.decodeFile(imgDecodableString)); 

      } else { 
       Toast.makeText(this, "You haven't picked Image",Toast.LENGTH_LONG).show(); 
      } 
     } catch (Exception e) 
     { 
      Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG) .show(); 
     } 
    } 
} 

도움이 되겠습니다.

+0

설명서를 읽어 내 doInBackground이 코드를 가지고

private void checkInternetAndUploadImage(final String uri) { if (Validator.isOnline(this)) { new UploadAsyncTask().execute(Uri.parse(uri)); } } 

그들은 명확하게 언급했다 –

+0

@jitesh mohite 나는 이미 그 코드를 구현하려했지만 작동하지 않는다 : –

+0

어떤 오류가 발생 했나요? –

답변

0

이 간단한 업로드를 사용할 수 있습니다. Cloudinary에 대한 NG 기능 :

Cloudinary cloudinary = new Cloudinary(Constants.CLOUDINARY_URL); 
    try { 
     FileInputStream is = new FileInputStream(new File(filePath)); 
     Uploader uploader = cloudinary.uploader(); 
     Map map = uploader.upload(is, new HashMap()); 
     return map; 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

자세한 설명은 여기가 : The order is like this: Take picture->save to file->upload to cloudinary

0

이다 나는 그것을 할 방법 :

갤러리 의도 내가 그것을 사용하고 내 로컬에 이미지를 저장 컨텐트 프로의 URI를 반환 (app/local) 디렉토리에 있습니다.

는이 말을 할 수 있습니다 :

다음
String local_uri = new SaveImageAsyncTask(cropImageView, 
           uri).execute().get(); 

내가 cloudinary에 이미지를 업로드 할이 URI를 사용

Map profilePicture = ObjectUtils.asMap("public_id", PreferencesManager.getInstance().getUserId() + 
          "/" + PreferencesManager.getInstance().getUserName() + "_PROFILE_PICTURE"); 
        profilePicture.put("uploadPrefix", "http://api.cloudinary.com"); 
        profilePicture.put("timestamp", System.currentTimeMillis()/1000); 
        Map imageUploadResult = CloudinaryManager.getInstance(Activity_ImageViewer.this).uploader(). 
          upload(new File(voids[0].getPath()), 
            profilePicture); 

        if (imageUploadResult.containsKey("url") /*&& backUploadResult.containsKey("url")*/) { 
         PreferencesManager.getInstance().setUSER_PROFILE_PICTURE_URL(String.valueOf(imageUploadResult.get("url"))); 
         //PreferencesManager.getInstance().setUserBackAssetUrl(String.valueOf(backUploadResult.get("url"))); 
         result = true; 
        }