|
@@ -392,41 +392,42 @@ class getUploadFiletoDirView(TemplateView):
|
|
|
else:
|
|
|
return response.json(903)
|
|
|
|
|
|
+ def getDir(self, fileType, fileName, fileCode, fileVersion, response):
|
|
|
+ try:
|
|
|
+ if fileCode != None and fileVersion != None:
|
|
|
+ path = '/'.join((BASE_DIR, 'static/Upgrade', fileType, fileCode, fileVersion)).replace('\\', '/') + '/'
|
|
|
+ else:
|
|
|
+ if fileType != 'IPC' and fileType != 'DVR' and fileType != 'NVR' and fileType != 'XVR':
|
|
|
+ path = '/'.join((BASE_DIR, "static/Upgrade", 'Other')).replace('\\', '/') + '/'
|
|
|
|
|
|
-def getDir(self, fileType, fileName, fileCode, fileVersion, response):
|
|
|
- try:
|
|
|
- if fileCode != None and fileVersion != None:
|
|
|
- path = '/'.join((BASE_DIR, 'static/Upgrade', fileType, fileCode, fileVersion)).replace('\\', '/') + '/'
|
|
|
- else:
|
|
|
- if fileType != 'IPC' and fileType != 'DVR' and fileType != 'NVR' and fileType != 'XVR':
|
|
|
- path = '/'.join((BASE_DIR, "static/Upgrade", 'Other')).replace('\\', '/') + '/'
|
|
|
-
|
|
|
- if not os.path.exists(path):
|
|
|
- os.makedirs(path)
|
|
|
- file_name = path + str(fileName)
|
|
|
- if os.path.exists(file_name):
|
|
|
- os.remove(file_name)
|
|
|
- destination = open(file_name, 'wb+')
|
|
|
- for chunk in fileName.chunks():
|
|
|
- destination.write(chunk)
|
|
|
- destination.close()
|
|
|
+ if not os.path.exists(path):
|
|
|
+ os.makedirs(path)
|
|
|
+ file_name = path + str(fileName)
|
|
|
+ if os.path.exists(file_name):
|
|
|
+ os.remove(file_name)
|
|
|
+ destination = open(file_name, 'wb+')
|
|
|
+ for chunk in fileName.chunks():
|
|
|
+ destination.write(chunk)
|
|
|
+ destination.close()
|
|
|
+ else:
|
|
|
+ file_name = path + str(fileName)
|
|
|
+ if os.path.exists(file_name):
|
|
|
+ os.remove(file_name)
|
|
|
+
|
|
|
+ destination = open(file_name, 'wb+')
|
|
|
+ for chunk in fileName.chunks():
|
|
|
+ destination.write(chunk)
|
|
|
+ destination.close()
|
|
|
+ except Exception as e:
|
|
|
+ errorInfo = traceback.format_exc()
|
|
|
+ print('上传文件错误: %s' % errorInfo)
|
|
|
+ return response.json(700, {'details': repr(e)})
|
|
|
else:
|
|
|
- file_name = path + str(fileName)
|
|
|
- if os.path.exists(file_name):
|
|
|
- os.remove(file_name)
|
|
|
-
|
|
|
- destination = open(file_name, 'wb+')
|
|
|
- for chunk in fileName.chunks():
|
|
|
- destination.write(chunk)
|
|
|
- destination.close()
|
|
|
- except Exception as e:
|
|
|
- errorInfo = traceback.format_exc()
|
|
|
- print('上传文件错误: %s' % errorInfo)
|
|
|
- return response.json(700, {'details': repr(e)})
|
|
|
- else:
|
|
|
- index = file_name.find('static/')
|
|
|
- filePath = file_name[index:]
|
|
|
- return response.json(0, {'filePath': filePath})
|
|
|
+ index = file_name.find('static/')
|
|
|
+ filePath = file_name[index:]
|
|
|
+ return response.json(0, {'filePath': filePath})
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
@csrf_exempt
|