This commit is contained in:
2023-08-12 13:46:00 +02:00
parent cb6de75a26
commit 7544646c08

View File

@@ -1,4 +1,4 @@
use reqwest::{Response, multipart::{Form, Part}, Body}; use reqwest::{Response, Body};
use tempfile::SpooledTempFile; use tempfile::SpooledTempFile;
use tokio_util::io::ReaderStream; use tokio_util::io::ReaderStream;
@@ -7,17 +7,17 @@ use crate::config;
use super::downloader::types::SpooledTempAsyncRead; use super::downloader::types::SpooledTempAsyncRead;
pub async fn convert_file(file: SpooledTempFile, file_type: String) -> Option<Response> { pub async fn convert_file(file: SpooledTempFile, file_type: String) -> Option<Response> {
let client = reqwest::Client::new(); let body = Body::wrap_stream(ReaderStream::new(SpooledTempAsyncRead::new(file)));
let async_file = Body::wrap_stream(ReaderStream::new(SpooledTempAsyncRead::new(file))); let response = reqwest::Client::new()
let file_part = Part::stream(async_file).file_name("file"); .post(
let form = Form::new() format!(
.text("format", file_type.clone()) "{}{}",
.part("file", file_part); config::CONFIG.converter_url,
file_type
let response = client )
.post(&config::CONFIG.converter_url) )
.multipart(form) .body(body)
.header("Authorization", &config::CONFIG.converter_api_key) .header("Authorization", &config::CONFIG.converter_api_key)
.send().await; .send().await;