-
I've developed a simple image upload application that stores the image paths in an SQLite database. While the images display correctly within the app after the initial upload, accessing them through the stored paths post-app closure consistently results in an "Internal Server Error." Expected Behavior: Users should be able to view previously uploaded images by accessing their stored paths in the SQLite database, even after closing and reopening the application. configuration "security": {
"csp": "default-src 'self'; img-src 'self'; asset: https://asset.localhost",
"assetProtocol": {
"enable": true,
"scope": [
"$HOME/**",
"$HOME/.myapp/files/**",
"$HOME/.myapp/images/**"
]
}
}
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
set .register_uri_scheme_protocol("asset", |_ctx, request| {
let cleaned_path = percent_encoding::percent_decode_str(&request.uri().path())
.decode_utf8()
.unwrap()
.as_bytes()[1..]
.to_vec();
let path_string = String::from_utf8(cleaned_path).unwrap_or_default();
let path = std::path::Path::new(&path_string);
match std::fs::read(path) {
Ok(data) => {
let content_type = if let Some(ext) = path.extension() {
if let Some(ext) = ext.to_str() {
match ext.to_lowercase().as_str() {
"jpg" | "jpeg" => "image/jpeg",
"png" => "image/png",
"gif" => "image/gif",
"webp" => "image/webp",
"bmp" => "image/bmp",
"ico" => "image/x-icon",
"svg" => "image/svg+xml",
_ => "image/*",
}
} else {
"image/*"
}
} else {
"image/*"
};
return tauri::http::Response::builder()
.status(200)
.header(tauri::http::header::CONTENT_TYPE, content_type)
.body(data)
.unwrap();
}
Err(e) => {
println!("error: {}", e.to_string());
return tauri::http::Response::builder()
.status(200)
.header(tauri::http::header::CONTENT_TYPE, "text/plain")
.body("failed to read file".as_bytes().to_vec())
.unwrap();
}
}
}) it worked for me. use |
Beta Was this translation helpful? Give feedback.
set
csp
tonull
,then add call
register_uri_scheme_protocol
on builder: