def get_href(self, filename, **kwargs): if not filename: return '' s = settings.GLOBAL fname = norm_filename(files.unicode_filename(filename, s.FILESYSTEM_ENCODING)) f = url_for('file_serving', filename=fname, **kwargs) return f
def save_file(self, filename, fobj, replace=False, convert=True): from uliweb.utils import files #get full path and converted filename fname = self.get_filename(filename, True, convert=convert) #save file and get the changed filename, because the filename maybe change when #there is duplicate filename(replace=False, if replace=True, then the filename #will not changed fname2 = files.save_file(fname, fobj, replace, self.buffer_size) s = settings.GLOBAL #create new filename according fname2 and filename, the result should be unicode return norm_filename(os.path.join(os.path.dirname(filename), files.unicode_filename(fname2, s.FILESYSTEM_ENCODING)))
def save_file(self, filename, fobj, replace=False, convert=True): from uliweb.utils import files #get full path and converted filename fname = self.get_filename(filename, True, convert=convert) #save file and get the changed filename, because the filename maybe change when #there is duplicate filename, if replace=True, then the filename #will not changed fname2 = files.save_file(fname, fobj, replace, self.buffer_size) s = settings.GLOBAL #create new filename according fname2 and filename, the result should be unicode return norm_filename(os.path.join(os.path.dirname(filename), files.unicode_filename(fname2, s.FILESYSTEM_ENCODING)))
def save_file(filename, fobj, replace=False): from uliweb import application from uliweb.utils import files assert hasattr(fobj, 'read'), "fobj parameter should be a file-like object" #get full path filename fname = get_filename(filename) s = application.settings.GLOBAL #change full path filename to filesystem filename fname1 = files.encode_filename(fname, s.HTMLPAGE_ENCODING, s.FILESYSTEM_ENCODING) #save file and get the changed filename, because the filename maybe change when #there is duplicate filename(replace=False, if replace=True, then the filename #will not changed fname2 = files.save_file(fname1, fobj, replace, application.settings.UPLOAD.BUFFER_SIZE) #create new filename according fname2 and filename, the result should be unicode return normfilename(os.path.join(os.path.dirname(filename), files.unicode_filename(fname2, s.FILESYSTEM_ENCODING)))