def export(file_id, file_name=None, folder=None, override=False): # 在存储桶中读取文件记录 grid_out = fw_files_storage.find_one({'filename': file_id}) item = SysUtils.grid_out_to_dict(grid_out) if item is None: return None # 设置文件路径,默认文件导出到临时目录 if file_name is None: file_name = item['filename'] if folder is None: folder = MyPath.temporary() file_path = os.path.join(folder, file_name) # 不设置覆写时,如果文件已存在,则跳过文件创建和写数据的操作 if not override and MyFile.exist(file_path): return file_path # 读取文件数据 data = grid_out.read() # 创建文件并写入数据 with open(file_path, 'wb') as file: file.write(data) return file_path
def fetch(self, firmware_id): grid_out = self.method_fs.find_one({'filename': firmware_id}) item = SysUtils.grid_out_to_dict(grid_out) if item is None: return None data = grid_out.read() print(item['aliases']) # save path file filename = self.FW_PATH + item['aliases'] outf = open(filename, 'wb') # 创建文件 outf.write(data) outf.close() return item['aliases']
def fetch(file_id): grid_out = fw_files_storage.find_one({'filename': file_id}) item = SysUtils.grid_out_to_dict(grid_out) return item