Exemplo n.º 1
0
 def execute(self):
     file1 = self._get_parameter("file")
     filex = Filex()
     filex.file_name = file1.filename
     filex.file_bytes = file1.value
     filex.creator_id = self._get_user_id()
     model_name = self._get_str_parameter("modelName")
     model_key = self._get_str_parameter("modelKey")
     filex.create_file(
         file1.filename,
         file1.value,
         self._get_user_id(),
         self._get_user_id(),
         model_name=model_name,
         model_key=model_key,
     )
     rtn = self._new_rtn()
     rtn.set_data(True)
     return rtn.to_json()
Exemplo n.º 2
0
def create_file(file_name, file_content, model_name, model_key, user_id, modifier_id):
    max_size = conf.get_upload_file_maximum_size(user_id)
    if len(file_content) > max_size:
        raise FileSizeExceededError(max_size / 1024 / 1024)
    filex = Filex()
    filex.file_name = file_name
    if "." in filex.file_name:            
        filex.file_type = filex.file_name.rsplit(".")[1]
    else:
        filex.file_type = ""
    filex.creator_id = user_id
    filex.model_name = model_name
    filex.model_key = model_key
    file_name = str(user_id) + "_" + str(model_name) + "_" + str(model_key) + "_" + file_name
    filex.save_path = os.sep + model_name + os.sep + file_name
    filex.root_path = os.sep + str(user_id) + os.sep + sysprop.get_sysprop_value("UPLOADFILE_ROOTPATH", default=conf.DEFAULT_UPLOADFILE_ROOTPATH)
    filex.file_size = len(file_content)
    filex.file_hash = ioutil.get_file_md5(file_content)
    _save_file(file_content, filex.root_path, filex.save_path)
    filex.put(modifier_id)
    return filex