我的要求是
不会重命名和压缩文件。让我在这里添加我的代码
@app.route('/temp/upload', methods=['POST'])
def upload():
if request.method == 'POST':
f = request.files['file']
random_string = generate_random(5)
print "Random string=> ", random_string # wqzhp
print "f.filename->>> ", f.filename # form3.pdf
fn = f.filename
fname = (fn).split(".")
random_file_name = fname[0] + '-' + random_string + "." + fname[1]
print "random_file_name>> ", random_file_name # form3-wqzhp.pdf
actual_file = os.path.join(load_path, random_file_name)
print "Actual file -> ", actual_file # uploadedDocs/1/form3-wqzhp.pdf
zip_f_name = actual_file + ".zip"
print "zip_f_name--> ", zip_f_name # uploadedDocs/1/form3-wqzhp.pdf.zip
f.save(zip_f_name)
zip_ref = zipfile.ZipFile(zip_f_name, 'r')
zip_ref.extractall(load_path)
zip_ref.close()
os.remove(zip_f_name)
if update_file_status(random_file_name, 0, csvid) is False:
return "update failed"
return "success"
解压缩zip时,只解压缩上传的原始文件。与重命名的文件压缩没有发生!如何在zip中保存重命名的文件?
任何线索!