ฉันได้รับรูปภาพจากแกลเลอรีสำเร็จแล้ว แต่ฉันไม่สามารถอัปโหลดรูปภาพไปยังเซิร์ฟเวอร์ได้เนื่องจากไฟล์เป็นโมฆะ มีรหัสใดบ้างที่ฉันพลาดที่จะเพิ่ม? ฉันเพิ่ม imageView.getPath แต่ฉันรับเฉพาะเส้นทางจากภาพจากกล้องไปยังเซิร์ฟเวอร์ และรับภาพว่างจากแกลเลอรี
ฉันได้รับเส้นทางนี้ content://com.android.providers.media.documents/document/image%3A5755 แต่ยังไม่สามารถอัปโหลดไปยังเซิร์ฟเวอร์ได้
private void getImageFromGallery(Intent data) {
mSelectedImgURI = data.getData();
mimeType = getImageExt(mSelectedImgURI);
uploadDialog.dismiss();
imgCategory.setImageURI(mSelectedImgURI);
}
private void getImageFromCamera(Intent data) {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
String tempFileName = System.currentTimeMillis() + ".jpg";
File destination = new File(Environment.getExternalStorageDirectory(),tempFileName);
FileOutputStream fo;
try {
destination.createNewFile();
fo = new FileOutputStream(destination);
fo.write(bytes.toByteArray());
fo.close();
mSelectedImgURI = Uri.fromFile(destination);
uploadDialog.dismiss();
imgCategory.setImageBitmap(thumbnail);
} catch (IOException e) {
Log.d(TAG, "Internal error - " + e.getLocalizedMessage());
}
}
public String getImageExt(Uri uri){
ContentResolver contentResolver = getApplicationContext().getContentResolver();
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
return mimeTypeMap.getExtensionFromMimeType(contentResolver.getType(uri));
}