Can files be handled with Tauri commands? #9566
-
I want to pass a PDF file received on the frontend to backend. The command I'm trying to execute looks like this: use std::fs::File;
#[tauri::command]
pub async fn handle_pdf(file: File) -> Result<&str, String> {
println!("{:?}", file);
Ok("")
} I anticipated that this wouldn't work straight away. Leaving aside the internal processing, I'm unsure about the type to use when receiving it as an argument... Currently, I'm encountering the following error:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
std::fs::File has no javascript or json representation so using it as a command arugments can't work. The argument on the rust side would be |
Beta Was this translation helpful? Give feedback.
std::fs::File has no javascript or json representation so using it as a command arugments can't work.
A similar problem on the other side: the javascript File also does not have a json representation so it can't be send directly. The only real solution here that i'm aware of is to send the file as plain binary.
The argument on the rust side would be
Vec<u8>
and on js ideally number[] but iirc the invoke api will convert Uint8arrays and arraybuffer to number[] for you (but it has to be number[] in the end for the ipc to work)