|
@@ -31,6 +31,121 @@ def upload_test(iurl):
|
|
|
|
|
|
return new_response.content
|
|
|
|
|
|
+@upload_app.route('/backstage/multiupload/<path:iurl>', methods=['POST'])
|
|
|
+def upload_multi_post(iurl):
|
|
|
+
|
|
|
+
|
|
|
+ mdPath = ""
|
|
|
+ new_response = requests.get(PORTAL_SERVER + 'contents?url=' + iurl)
|
|
|
+
|
|
|
+ obj = json.loads(new_response.content.decode('utf-8'))
|
|
|
+
|
|
|
+ if len(obj) > 0:
|
|
|
+ for key, value in obj[0].items():
|
|
|
+ if key == 'path':
|
|
|
+ mdPath = value.replace('\\', '/')
|
|
|
+
|
|
|
+ mdPath = mdPath[0:mdPath.rfind('/')+1]
|
|
|
+
|
|
|
+ isProduct = False
|
|
|
+ if mdPath.find("設計家具") >= 0 or mdPath.find("模組系統櫃") >= 0:
|
|
|
+ isProduct = True
|
|
|
+
|
|
|
+ filepath = ""
|
|
|
+ itype = ""
|
|
|
+ print("markdown path is" + mdPath)
|
|
|
+
|
|
|
+ if iurl == "title":
|
|
|
+ itype = iurl
|
|
|
+ filepath = iurl
|
|
|
+ else:
|
|
|
+ itype = iurl[0:iurl.find("/")]
|
|
|
+ filepath = iurl[iurl.rfind("/")+1:]
|
|
|
+
|
|
|
+ if request.method == 'POST':
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ """ if 'file' not in request.files:
|
|
|
+
|
|
|
+ return redirect(request.url) """
|
|
|
+ if len(request.files) == 0:
|
|
|
+ aa = {"success": 0}
|
|
|
+ return aa
|
|
|
+ else:
|
|
|
+ n=0
|
|
|
+ filelink = ''
|
|
|
+ for i in request.files:
|
|
|
+ n+=1
|
|
|
+ fname = 'image' + str(n)
|
|
|
+ file = request.files[fname]
|
|
|
+ print("The file is at" + filepath)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ """ if file.filename == '':
|
|
|
+
|
|
|
+ return redirect(request.url) """
|
|
|
+ oimgtype = file.filename[file.filename.rfind(".")+1:]
|
|
|
+ oimgtypeName = oimgtype
|
|
|
+ if oimgtype.lower() == 'jpg':
|
|
|
+ oimgtypeName = 'jpeg'
|
|
|
+
|
|
|
+ if file and not isProduct:
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if filepath == "title":
|
|
|
+ sitepath = UPLOAD_PATH_MAP[0][2] + "/static/img/title/"
|
|
|
+ else:
|
|
|
+ sitepath = mdPath + "/img/"
|
|
|
+
|
|
|
+
|
|
|
+ wfname = str(uuid.uuid4()).replace('-','') + ".webp"
|
|
|
+ owfname = wfname.replace('webp', oimgtype)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ wpath = os.getcwd() + "/backstage/upload/" + filepath+"/img/"
|
|
|
+ owpath = os.getcwd() + "/backstage/upload/" + filepath+"/img/orig/"
|
|
|
+ print("1wpath is " + wpath)
|
|
|
+ print("1owpath is " + owpath)
|
|
|
+
|
|
|
+ if not os.path.exists(wpath):
|
|
|
+ os.makedirs(wpath)
|
|
|
+ if not os.path.exists(owpath):
|
|
|
+ os.makedirs(owpath)
|
|
|
+ if not os.path.exists(sitepath):
|
|
|
+ os.makedirs(sitepath)
|
|
|
+
|
|
|
+ image_object = Image.open(file)
|
|
|
+ image_object.save(owpath+owfname)
|
|
|
+ if image_object.size[0] > 1000:
|
|
|
+ image_object.thumbnail(size=((1600, 1600)))
|
|
|
+ image_object.save(wpath+wfname)
|
|
|
+ image_object.save(sitepath+wfname)
|
|
|
+ print("Loc1a: " + wpath+wfname)
|
|
|
+ print("Loc1b: " + owpath+wfname)
|
|
|
+ print("Loc2: " + sitepath+wfname)
|
|
|
+ print(filepath)
|
|
|
+
|
|
|
+
|
|
|
+ filelink += wfname + ";;;"
|
|
|
+ print(filelink)
|
|
|
+ aa = {"success": 1, "fileurl": filelink}
|
|
|
+ return aa
|
|
|
+
|
|
|
+ if request.method == 'GET':
|
|
|
+ print('GET')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ aa = {"success": 1, "file": {"url": "http://www.choozmo.com/images/logo%20%281%29.webp", }}
|
|
|
+ return aa
|
|
|
|
|
|
@upload_app.route('/backstage/upload/<path:iurl>', methods=['POST'])
|
|
|
def upload_post(iurl):
|
|
@@ -76,6 +191,7 @@ def upload_post(iurl):
|
|
|
return aa
|
|
|
else:
|
|
|
file = request.files['image']
|
|
|
+
|
|
|
print("The file is at" + filepath)
|
|
|
|
|
|
|
|
@@ -127,6 +243,7 @@ def upload_post(iurl):
|
|
|
print("Loc1a: " + wpath+wfname)
|
|
|
print("Loc1b: " + owpath+wfname)
|
|
|
print("Loc2: " + sitepath+wfname)
|
|
|
+ print(filepath)
|
|
|
|
|
|
|
|
|
aa = {"success": 1, "file": {"url": "/backstage/upload/" +
|