uploading zip as formdata, storing it in config-temp
This commit is contained in:
@@ -61,9 +61,12 @@ module.exports = {
|
|||||||
if (!files.length) {
|
if (!files.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("zipfile", files[0]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await api.put("/api/config/restore", files[0]);
|
await api.put("config/restore", formData);
|
||||||
SvelteComponents.showDialog("Message", {
|
SvelteComponents.showDialog("Message", {
|
||||||
title: "Success",
|
title: "Success",
|
||||||
message: "Configuration restored",
|
message: "Configuration restored",
|
||||||
|
|||||||
@@ -295,15 +295,33 @@ class ConfigDownloadHandler(bbctrl.APIHandler):
|
|||||||
|
|
||||||
class ConfigRestoreHandler(bbctrl.APIHandler):
|
class ConfigRestoreHandler(bbctrl.APIHandler):
|
||||||
def put(self):
|
def put(self):
|
||||||
zip_file = self.request.files['file'][0]
|
if 'zipfile' not in self.request.files:
|
||||||
if not os.path.exists('./config-temp'):
|
raise HTTPError(401,'No file uploaded')
|
||||||
os.mkdir('./config-temp')
|
|
||||||
|
|
||||||
if not os.path.exists(self.get_upload()):
|
self.get_log('ConfigRestoreHandler').info('self.request: {}'.format(str(self.request)))
|
||||||
os.mkdir(self.get_upload())
|
|
||||||
|
zip_file = self.request.files['zipfile'][0]
|
||||||
|
|
||||||
zip_path = os.path.join("./temp", zip_file['filename'])
|
temp_dir = './config-temp';
|
||||||
print(zip_path)
|
if not os.path.exists(temp_dir):
|
||||||
|
os.mkdir(temp_dir)
|
||||||
|
|
||||||
|
fmt = socket.gethostname() + '-%Y%m%d.zip'
|
||||||
|
filename = datetime.date.today().strftime(fmt)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(temp_dir+filename,'wb') as f:
|
||||||
|
f.write(zip_file['body'])
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPError(500, f"Unexpected error: {str(e)}")
|
||||||
|
# if not os.path.exists(self.get_upload()):
|
||||||
|
# os.mkdir(self.get_upload())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# zip_path = os.path.join("./temp", zip_file['filename'])
|
||||||
|
# print(zip_path)
|
||||||
# with open(zip_path, 'wb') as f:
|
# with open(zip_path, 'wb') as f:
|
||||||
# f.write(zip_file['body'])
|
# f.write(zip_file['body'])
|
||||||
|
|
||||||
@@ -313,10 +331,6 @@ class ConfigRestoreHandler(bbctrl.APIHandler):
|
|||||||
# for root, dirs, files in os.walk("./temp"):
|
# for root, dirs, files in os.walk("./temp"):
|
||||||
# for files in files:
|
# for files in files:
|
||||||
|
|
||||||
|
|
||||||
self.write("File processed successfully.")
|
|
||||||
self.finish()
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigSaveHandler(bbctrl.APIHandler):
|
class ConfigSaveHandler(bbctrl.APIHandler):
|
||||||
def put_ok(self): self.get_ctrl().config.save(self.json)
|
def put_ok(self): self.get_ctrl().config.save(self.json)
|
||||||
|
|||||||
Reference in New Issue
Block a user