Sudeep
Sudeep

Reputation: 129

Cannot upload the image taken directly from camera

Hello i am having a problem in uploading the picture directly from camera. The error is:

/mnt/sdcard/Phoenix/default: open failed: ENOENT (No such file or directory)

I have tried many other methods but i am facing the same problem of No such file or directory. My code is as follows:

if (options[item].equals("Take Photo")) {
                        dialog.dismiss();
                        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp.jpg");
                        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
                        startActivityForResult(intent, PICK_IMAGE_CAMERA);
                    }

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        inputStreamImg = null;
        if (requestCode == PICK_IMAGE_CAMERA) {
            try {

                File f = new File(Environment.getExternalStorageDirectory().toString());
                for (File temp : f.listFiles()) {
                    if (temp.getName().equals("temp.jpg")) {
                        f = temp;
                        break;
                    }
                }
                try {
                    BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
                    bitmapPrescribedMed = BitmapFactory.decodeFile(f.getAbsolutePath(), bitmapOptions);
                    imgPrescribedMedicinePath = android.os.Environment
                            .getExternalStorageDirectory()
                            + File.separator
                            + "Phoenix" + File.separator + "default";
                    f.delete();
                    OutputStream outFile = null;
                    File file = new File(imgPrescribedMedicinePath, String.valueOf(System.currentTimeMillis()) + ".jpg");
                    try {
                        outFile = new FileOutputStream(file);
                        bitmapPrescribedMed.compress(Bitmap.CompressFormat.JPEG, 85, outFile);
                        outFile.flush();
                        outFile.close();
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

Can somebody please help me?

Upvotes: 0

Views: 73

Answers (1)

Vibhu Goel
Vibhu Goel

Reputation: 161

We actually write our file in external storage . try to add the folowing in your AndroidManifest.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

If that don't work try to reproduce multiple times, if that work once then work everytime it could maybe say that the module need to create image in a custom local directory

Upvotes: 1

Related Questions