Skip to content

Commit 853ed46

Browse files
ish1416FabianLars
andauthored
fix(android): improve error handling for external storage file access (#14442)
Co-authored-by: Fabian-Lars <github@fabianlars.de>
1 parent 53611c4 commit 853ed46

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch:bug
3+
---
4+
5+
Fixed 500 error when accessing local video files in Android external storage directory via `convertFileSrc`. Added better error handling and logging for Android external storage access to help diagnose permission and accessibility issues.

crates/tauri/src/protocol/asset.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,29 @@ fn get_response(
4848
return resp.status(403).body(Vec::new().into()).map_err(Into::into);
4949
}
5050

51-
let (mut file, len, mime_type, read_bytes) = crate::async_runtime::safe_block_on(async move {
52-
let mut file = File::open(&path).await?;
51+
// Separate block for easier error handling
52+
let mut file = match crate::async_runtime::safe_block_on(File::open(path.clone())) {
53+
Ok(file) => file,
54+
Err(e) => {
55+
#[cfg(target_os = "android")]
56+
{
57+
if path.starts_with("/storage/emulated/0/Android/data/") {
58+
log::error!("Failed to open Android external storage file '{}': {}. This may be due to missing storage permissions.", path, e);
59+
}
60+
}
61+
return if e.kind() == std::io::ErrorKind::NotFound {
62+
log::error!("File does not exist at path: {}", path);
63+
return resp.status(404).body(Vec::new().into()).map_err(Into::into);
64+
} else if e.kind() == std::io::ErrorKind::PermissionDenied {
65+
log::error!("Missing OS permission to access path \"{}\": {}", path, e);
66+
return resp.status(403).body(Vec::new().into()).map_err(Into::into);
67+
} else {
68+
Err(e.into())
69+
};
70+
}
71+
};
5372

73+
let (mut file, len, mime_type, read_bytes) = crate::async_runtime::safe_block_on(async move {
5474
// get file length
5575
let len = {
5676
let old_pos = file.stream_position().await?;

0 commit comments

Comments
 (0)