diff --git a/src/database/globals.rs b/src/database/globals.rs
index de97578b..55256443 100644
--- a/src/database/globals.rs
+++ b/src/database/globals.rs
@@ -7,6 +7,7 @@ use ruma::{
 use rustls::{ServerCertVerifier, WebPKIVerifier};
 use std::{
     collections::{BTreeMap, HashMap},
+    fs,
     path::PathBuf,
     sync::{Arc, RwLock},
     time::{Duration, Instant},
@@ -137,7 +138,7 @@ impl Globals {
             .as_ref()
             .map(|secret| jsonwebtoken::DecodingKey::from_secret(secret.as_bytes()).into_static());
 
-        Ok(Self {
+        let s = Self {
             globals,
             config,
             keypair: Arc::new(keypair),
@@ -152,7 +153,11 @@ impl Globals {
             bad_event_ratelimiter: Arc::new(RwLock::new(BTreeMap::new())),
             bad_signature_ratelimiter: Arc::new(RwLock::new(BTreeMap::new())),
             servername_ratelimiter: Arc::new(RwLock::new(BTreeMap::new())),
-        })
+        };
+
+        fs::create_dir_all(s.get_media_folder())?;
+
+        Ok(s)
     }
 
     /// Returns this server's keypair.
diff --git a/src/database/media.rs b/src/database/media.rs
index 205f3a65..b81e8633 100644
--- a/src/database/media.rs
+++ b/src/database/media.rs
@@ -4,11 +4,7 @@ use image::{imageops::FilterType, GenericImageView};
 use super::abstraction::Tree;
 use crate::{utils, Error, Result};
 use std::{mem, sync::Arc};
-use tokio::{
-    fs::{self, File},
-    io::AsyncReadExt,
-    io::AsyncWriteExt,
-};
+use tokio::{fs::File, io::AsyncReadExt, io::AsyncWriteExt};
 
 pub struct FileMeta {
     pub content_disposition: Option<String>,
@@ -50,7 +46,6 @@ impl Media {
         );
 
         let path = globals.get_media_file(&key);
-        fs::create_dir_all(path.parent().unwrap()).await?;
         let mut f = File::create(path).await?;
         f.write_all(file).await?;
 
@@ -89,7 +84,6 @@ impl Media {
         );
 
         let path = globals.get_media_file(&key);
-        fs::create_dir_all(path.parent().unwrap()).await?;
         let mut f = File::create(path).await?;
         f.write_all(file).await?;
 
@@ -333,7 +327,6 @@ impl Media {
                 );
 
                 let path = globals.get_media_file(&thumbnail_key);
-                fs::create_dir_all(path.parent().unwrap()).await?;
                 let mut f = File::create(path).await?;
                 f.write_all(&thumbnail_bytes).await?;