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;
}
}
}`
와우, 그랬어. 감사! –