1

I keep getting a file not found exception even though the path exists. The path is taken from were I originally created the file, so I assume the path is correct. The error happens at the FileInputStream mark below by error.

This is the error: W/System.err? java.io.FileNotFoundException: /file:/storage/emulated/0/footyman/img_1429035461315.jpg: open failed: ENOENT (No such file or directory)

 public static void addProfilePic(final Uri path,final String imgName) { new AsyncTask<Void, Void, String>() { @Override protected String doInBackground(Void... par) { String done; try { // Retrieve storage account from connection-string. CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString); // Create the blob client. CloudBlobClient blobClient = storageAccount.createCloudBlobClient(); // Retrieve reference to a previously created container. CloudBlobContainer container = blobClient.getContainerReference("profilepics"); // Define the path to a local file. final String filePath = path.toString(); Log.i("filepath", filePath); // Create or overwrite the "myimage.jpg" blob with contents from a local file. CloudBlockBlob blob = container.getBlockBlobReference(imgName); File source = new File(path.toString()); // error here blob.upload(new FileInputStream(source.toURI().getPath()), source.length()); done = "true"; } catch (Exception e) { // Output the stack trace. done = "false"; e.printStackTrace(); } return done; } protected void onPostExecute(String done) { if (done.equals("true")) { Log.i("add pic", "success"); } else { Log.i("add pic", "failed"); } } }.execute(); } } 

2 Answers 2

1

/file:/storage/emulated/0/footyman/img_1429035461315.jpg remove the '/file:' so you only use /storage/emulated/0/footyman/img_1429035461315.jpg

Sign up to request clarification or add additional context in comments.

Comments

0

Your URI looks malformed and should be like this:

file:///storage/emulated/0/footyman/img_1429035461315.jpg

1 Comment

I tried hard code this uri in but to no the exact same error still appears

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.