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
files that are uploaded in the django-ckeditor5 to a ftp server are overwritten if they share the same name. i added some code to fix this. i just wanted to leave this here in case anyone else has the same problem. i am just an amateur and not really experienced with this whole "pull request" stuff.
So here is a possible fix:
I changed the original _put_file function in ftp.py to:
from django.utils.crypto import get_random_string
def _put_file(self, name, content) -> str:
# Connection must be open!
try:
self._mkremdirs(os.path.dirname(name))
pwd = self._connection.pwd()
self._connection.cwd(os.path.dirname(name))
# Rename the new file before saving if there is already a file with an
# identical name in the directory
files_in_dir = self.listdir(pwd)[1]
for file in files_in_dir:
if file == name:
while file == name:
splitted_file_str = os.path.splitext(name)
file_root = splitted_file_str[0]
file_ext = splitted_file_str[1]
name = "%s_%s%s" % (file_root, get_random_string(7), file_ext)**
# Store the file
self._connection.storbinary(
"STOR " + os.path.basename(name),
content.file,
content.DEFAULT_CHUNK_SIZE,
)
self._connection.cwd(pwd)
return name
....
i also changed the _save func of ftp.py to:
def _save(self, name, content):
content.open()
self._start_connection()
name = self._put_file(name, content)
content.close()
return name
that's it. maybe this is useful for someone.
The text was updated successfully, but these errors were encountered:
Hi @HerrEich thanks for opening this. Many other backends already implement this feature as you just need to overwrite get_available_name, would you be interested in contributing it to FTP?
Hi,
files that are uploaded in the django-ckeditor5 to a ftp server are overwritten if they share the same name. i added some code to fix this. i just wanted to leave this here in case anyone else has the same problem. i am just an amateur and not really experienced with this whole "pull request" stuff.
So here is a possible fix:
I changed the original _put_file function in ftp.py to:
....
i also changed the _save func of ftp.py to:
that's it. maybe this is useful for someone.
The text was updated successfully, but these errors were encountered: