def add_file(self,fobj): from uliweb.utils import files artifact_dpath = self.get_artifact_dpath() if not os.path.exists(artifact_dpath): os.makedirs(artifact_dpath) fname = "%s"%(int(time.time()*1000000)) fpath = os.path.join(artifact_dpath,fname) files.save_file(fpath,fobj) return fname,self.normalize_path(fobj.filename)
def add_file(self,fobj): from uliweb.utils import files artifact_dpath = self.get_artifact_dpath() if not os.path.exists(artifact_dpath): os.makedirs(artifact_dpath) log.info("mkdir %s"%(artifact_dpath)) fname = "%s"%(int(time.time()*1000000)) fpath = os.path.join(artifact_dpath,fname) files.save_file(fpath,fobj) fsize = os.path.getsize(fpath) filename = getattr(fobj,"filename",None) if not filename: filename = getattr(fobj,"name") fpath_normalized = self.normalize_path(filename) log.info("store %s in %s,size: %s"%(repr(fpath_normalized),fpath,fsize)) return fname,fpath_normalized,fsize
def add_file(self, fobj): from uliweb.utils import files artifact_dpath = self.get_artifact_dpath() if not os.path.exists(artifact_dpath): os.makedirs(artifact_dpath) log.info("mkdir %s" % (artifact_dpath)) fname = "%s" % (int(time.time() * 1000000)) fpath = os.path.join(artifact_dpath, fname) files.save_file(fpath, fobj) fsize = os.path.getsize(fpath) filename = getattr(fobj, "filename", None) if not filename: filename = getattr(fobj, "name") fpath_normalized = self.normalize_path(filename) log.info("store %s in %s,size: %s" % (repr(fpath_normalized), fpath, fsize)) return fname, fpath_normalized, fsize
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)))