You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pub async fn get_mime_from_url(public_link: &str) -> Result<String, ApiError> {
// Create a reqwest client
let client = Client::new();
// Make a GET request to fetch the first 512 bytes of the file
// Replace with the actual URL
let resp = client
.get(public_link)
.header(reqwest::header::RANGE, "bytes=0-2048")
.send()
.await
.map_err(|e| {
eprintln!("Error fetching file: {}", e);
ApiError {
status: "issue-fetching-file".to_string(),
message: "Error fetching file for get_mime_from_url".to_string(),
}
})?
.bytes()
.await
.map_err(|e| {
eprintln!("Error fetching bytes file: {}", e);
ApiError {
status: "issue-fetching-file".to_string(),
message: "Error fetching bytes for get_mime_from_url".to_string(),
}
})?;
// Infer expects a &[u8]
let bytes = resp.as_ref();
println!("RES: {:?}", resp.len());
// Create an instance of Infer to guess the file type
let infer = Infer::new();
let kind = infer.get(bytes);
println!("KIND {:?}", kind);
// Match the result and print the file type
match kind {
Some(kind) => println!("File type: {}", kind.mime_type()),
None => println!("Could not determine file type"),
}
Ok("".to_string())
}
As title. We want to be able to set mime type for users on a could service without having to download 100gb files. It's possible with Node mime.
The text was updated successfully, but these errors were encountered: