即使路径存在,我仍会收到未找到文件异常。该路径是从我最初创建文件时获取的,因此我认为该路径是正确的。错误发生在下面的FileInputStream标记处,错误。

这是错误:W / System.err? java.io.FileNotFoundException:/file:/storage/emulated/0/footyman/img_1429035461315.jpg:打开失败:ENOENT(没有这样的文件或目录)

     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();
    }
}

最佳答案

/file:/storage/emulated/0/footyman/img_1429035461315.jpg删除“ / file:”,以便仅使用/storage/emulated/0/footyman/img_1429035461315.jpg

08-27 14:50