即使路径存在,我仍然会收到文件未找到的异常。路径取自我最初创建的文件,所以我假设路径是正确的。错误发生在下面的FileInputStream标记处。
这是错误:W / System.err? java.io.FileNotFoundException:/file:/storage/emulated/0/footyman/img_1429035461315.jpg:open failed: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();
}
}
答案 0 :(得分:1)
/file:/storage/emulated/0/footyman/img_1429035461315.jpg删除'/ file:'所以你只使用/storage/emulated/0/footyman/img_1429035461315.jpg
答案 1 :(得分:0)
您的URI看起来格格不入,应该是这样的:
文件:///storage/emulated/0/footyman/img_1429035461315.jpg 强>