Java.io.filenotfoundexception When Uploading Pics From Camera Using Http Post Multipartentity
I am trying to upload pic from my device to the server.Uploading pic from gallery is working fine but uploading pic from camera gives error java.io.FileNotFoundException: /storage
Solution 1:
Excepstion says that your file donot exists on the specified path
have a check on the file path
protectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmapphoto= (Bitmap) data.getExtras().get("data");
ByteArrayOutputStreambytes=newByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
//you can create a new file name "test.jpg" in sdcard folder.Filef=newFile(Environment.getExternalStorageDirectory()
+ File.separator + "test.jpg");
try {
f.createNewFile();
//write the bytes in fileFileOutputStreamfo=newFileOutputStream(f);
fo.write(bytes.toByteArray());
// remember close de FileOutput
fo.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (f.exists()) {
Toast.makeText(this, "Image Found : "+f.getAbsolutePath().toString(), Toast.LENGTH_SHORT).show();
newUpdateProfilePicApi().execute(f.getAbsolutePath().toString());
}else{
Toast.makeText(this, "Image Not Found", Toast.LENGTH_SHORT).show();
}
}
}
and your intent
IntentcameraIntent=newIntent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
Solution 2:
The problem is that System.currentTimeMillis()
changes rapidly so between you asking for a camera input and receiving the image the value is different and you can't find the file (and that's only if you specified the file name beforehand).
I can only recommend reading and using the documentation for obtaining a full-sized image from camera. The only difference is that instead of getExternalStoragePublicDirectory()
you'd use getExternalFilesDir()
because you don't want the image public.
If you follow the guide, the image path will be stored in String mCurrentPhotoPath;
so you can upload it and delete it afterwards easily.
Post a Comment for "Java.io.filenotfoundexception When Uploading Pics From Camera Using Http Post Multipartentity"