2016-09-28 3 views
0

현재 카메라 앱을 시작한 다음 이미지를 가져 와서 구문 분석 서버에 업로드하는 버튼을 만들려고하는데 이미지가 올바르게 업로드되지 않는 것 같습니다. 그것은 충돌하지만 나에게 에러 출력을주지는 못한다. 왜 이미지가 파일로 업로드 될지 모르겠다. 내 코드는 아래와 같습니다. `private File imageFile; TextView imageFilePath; EditText editTxt;사진을 찍은 후 이미지를 업로드하는 중입니다.

String selectedVenue; 
String id; 
String currentUser; 
ParseGeoPoint location; 
String venueType; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_gen_post); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
    editTxt = (EditText) findViewById(R.id.txtInput); 

    Intent i = getIntent(); 
    location = new ParseGeoPoint(i.getDoubleExtra("Lat",0.0),i.getDoubleExtra("Lon",0.0)); 
    currentUser= ParseUser.getCurrentUser().getUsername(); 

} 
@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    onBackPressed(); 
    return true; 
} 

public void uploadComment(View view){ 
    String input = editTxt.getText().toString(); 
    Log.i("AppInfo", "uploading"); 
    if(input.equals("")|| input.equals(null)){ 
     Toast.makeText(this,"You must write something",Toast.LENGTH_SHORT); 
    } 
    else{ 
     ParseObject object = new ParseObject("UserCommentary"); 
     if(imageFile != null){ 
      Bitmap bitmapImage = BitmapFactory.decodeFile(imageFile.getAbsolutePath()); 
      ByteArrayOutputStream oStream = new ByteArrayOutputStream(); 
      bitmapImage.compress(Bitmap.CompressFormat.JPEG, 50, oStream); 
      byte[] byteArray = oStream.toByteArray(); 
      object.put("comment", input); 
      object.put("Location",location); 
      object.put("image",true); 
      object.put("imgFile",byteArray); 
     } 
     else { 
      object.put("comment", input); 
      object.put("Location",location); 
      object.put("image",false); 
     } 
     object.saveInBackground(); 
    } 
    onBackPressed(); 


} 

public void takePhoto(View view) { 

    Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    imageFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), currentUser+".jpeg"); 
    Uri tempuri = Uri.fromFile(imageFile); 
    takePicture.putExtra(MediaStore.EXTRA_OUTPUT, tempuri); 
    takePicture.putExtra(MediaStore.EXTRA_VIDEO_QUALITY,1); 
    startActivityForResult(takePicture, 0); 
} 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if(requestCode == 0){ 
     switch (resultCode){ 
      case Activity.RESULT_OK: 
       if(imageFile.exists()){ 
        imageFilePath.setText(imageFile.getAbsolutePath()); 

       } 
       else{ 
        Toast.makeText(this,"Error taking picture",Toast.LENGTH_LONG).show(); 
       } 
       break; 
      case Activity.RESULT_CANCELED: 
       break; 
      default : 
       break; 
     } 
    } 
}` 

답변

0

다음은 Parse cloud에 이미지를 업로드하는 방법에 대한 자습서입니다.

// Create the ParseFile passing byte array (image) 
ParseFile file = new ParseFile("androidbegin.png", image); 
// Upload the image into Parse Cloud 
file.saveInBackground(); 

한 후 다음과 같이 해석 객체에 저장이 구문 분석 파일을 사용 :

구현의 비교에서

http://www.androidbegin.com/tutorial/android-parse-com-image-upload-tutorial/

및 것은 하나의, 당신이 다음 코드를 놓치고 생각 튜토리얼

object.put("imgFile",file); 

희망이 있습니다.

+0

와우, 그랬어. 감사! –

관련 문제