Improve file mime guessing

This commit is contained in:
timvisee 2018-03-28 14:12:33 +02:00
parent b2e63b9efc
commit 8ea1b5971c
No known key found for this signature in database
GPG key ID: A28432A0AE6E6306

View file

@ -3,7 +3,7 @@ use std::io::BufReader;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use mime_guess::{get_mime_type, Mime}; use mime_guess::{guess_mime_type, Mime};
use openssl::symm::encrypt_aead; use openssl::symm::encrypt_aead;
use reqwest::{ use reqwest::{
Client, Client,
@ -284,21 +284,14 @@ impl<'a> FileData<'a> {
// Get the file name // Get the file name
let name = match path.file_name() { let name = match path.file_name() {
Some(name) => name.to_str().expect("failed to convert string"), Some(name) => name.to_str().unwrap_or("file"),
None => return Err(UploadError::FileError), None => "file",
};
// Get the file extention
// TODO: handle cases where the file doesn't have an extention
let ext = match path.extension() {
Some(ext) => ext.to_str().expect("failed to convert string"),
None => return Err(UploadError::FileError),
}; };
Ok( Ok(
Self { Self {
name, name,
mime: get_mime_type(ext), mime: guess_mime_type(path),
} }
) )
} }