|
|
@ -290,16 +290,21 @@ class Directory:
|
|
|
|
|
|
|
|
|
|
|
|
if filename is None:
|
|
|
|
if filename is None:
|
|
|
|
if type(filedata) is str:
|
|
|
|
if type(filedata) is str:
|
|
|
|
filename = self._sanitize_filename(os.path.basename(filedata))
|
|
|
|
filename = self.filesystem._sanitize_filename(os.path.basename(filedata))
|
|
|
|
elif type(filedata) is file:
|
|
|
|
elif type(filedata) is file:
|
|
|
|
if type(filedata.name) is str:
|
|
|
|
if type(filedata.name) is str:
|
|
|
|
filename = self._sanitize_filename(filedata.name)
|
|
|
|
filename = self.filesystem._sanitize_filename(filedata.name)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
# We could not determine the filename for the input... let's generate something.
|
|
|
|
# We could not determine the filename for the input... let's generate something.
|
|
|
|
filename = ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(15))
|
|
|
|
filename = ''.join(random.choice(string.ascii_lowercase + string.digits) for x in range(15))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
raise UploadException("The given file is not a valid string or file object.")
|
|
|
|
raise UploadException("The given file is not a valid string or file object.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new_file = self.filesystem.upload(filedata)
|
|
|
|
|
|
|
|
new_file.attach(self, filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new_file
|
|
|
|
|
|
|
|
|
|
|
|
def attach(self, directory, filename=None, **kwargs):
|
|
|
|
def attach(self, directory, filename=None, **kwargs):
|
|
|
|
"""Attach this Directory to a Directory in the filesystem.
|
|
|
|
"""Attach this Directory to a Directory in the filesystem.
|
|
|
|
|
|
|
|
|
|
|
|