From 8031489327ed1aa0f0497b224b84c568aa56f83f Mon Sep 17 00:00:00 2001 From: Fabian Heller Date: Wed, 7 Oct 2020 17:18:59 +0200 Subject: [PATCH] Fix: Use forward slash on Windows On Windows a backslash was used as path separator although for remote file systems file like SSHFS it must always be a forward slash. --- storages/base.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/storages/base.py b/storages/base.py index f919b78f1..0f0f7d051 100644 --- a/storages/base.py +++ b/storages/base.py @@ -1,3 +1,6 @@ +import os +import posixpath + from django.core.exceptions import ImproperlyConfigured from django.core.files.storage import Storage @@ -22,3 +25,15 @@ def __init__(self, **settings): def get_default_settings(self): return {} + + def generate_filename(self, filename): + """ + Validate the filename by calling get_valid_name() and return a filename + to be passed to the save() method. + """ + # `filename` may include a path as returned by FileField.upload_to. + dirname, filename = os.path.split(filename) + + # Use posixpath so it will not use "\\" on Windows + return posixpath.normpath(posixpath.join(dirname, self.get_valid_name(filename))) +