-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http POST: missing boundary with content-type "multipart/form-data" #2118
Comments
This is a great finding, thankyou! I see a couple options here:
|
The issue is that we need to use the dedicated multipart APIs to support this: But the crate's design for multipart is filled with references, so it's tricky to implement it without introducing a breaking change. |
Would be nice if someone could provide an example how a custom command would look like for sending multipart form with files if this feature is not going to natively supported any time soon. |
@mgedgaudas #[tauri::command]
async fn upload_file(file: std::path::PathBuf) -> Result<(), String> {
// ^We expect the frontend to send a file path.
let client = reqwest::Client::new();
let file_name = file.file_name().unwrap().to_string_lossy().to_string();
let file_content = tokio::fs::read(file).await.map_err(|err| err.to_string())?;
let part = reqwest::multipart::Part::bytes(file_content).file_name(file_name);
let form = reqwest::multipart::Form::new().part("file", part);
client
.post("URL_HERE")
.multipart(form)
.send()
.await
.map_err(|err| err.to_string())?;
Ok(())
} You need to enable the |
Currently it is not possible to use "multipart/form-data" as content-type posting form-data with the http module due to missing boundary.
Example using the JS-API setting content-type by hand resulting in missing boundary:
This might be an issue with attohttpc, leaving the content type blank the content-type defaults to "application/x-www-form-urlencoded".
I am using the latest version of tauri (1.0.0-beta.4).
The text was updated successfully, but these errors were encountered: