@@ -2,6 +2,7 @@ use actix_web::error::ErrorInternalServerError;
|
||||
use aws_sdk_s3::{error::SdkError, primitives::ByteStream, Client as S3Client};
|
||||
use mime_guess::mime;
|
||||
use std::str::FromStr;
|
||||
use infer::get;
|
||||
|
||||
/// Загружает файл в S3 хранилище.
|
||||
pub async fn upload_to_s3(
|
||||
@@ -101,4 +102,21 @@ pub async fn get_s3_filelist(client: &S3Client, bucket: &str) -> Vec<[std::strin
|
||||
}
|
||||
}
|
||||
filenames
|
||||
}
|
||||
|
||||
pub fn detect_mime_type(bytes: &[u8]) -> Option<String> {
|
||||
let kind = get(bytes)?;
|
||||
Some(kind.mime_type().to_string())
|
||||
}
|
||||
|
||||
pub fn get_extension_from_mime(mime_type: &str) -> Option<&str> {
|
||||
match mime_type {
|
||||
"image/jpeg" => Some("jpg"),
|
||||
"image/png" => Some("png"),
|
||||
"image/gif" => Some("gif"),
|
||||
"image/webp" => Some("webp"),
|
||||
"image/heic" => Some("heic"),
|
||||
"image/tiff" => Some("tiff"),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user