|
@@ -31,6 +31,121 @@ def upload_test(iurl):
|
|
|
# print(my_dict[0].items())
|
|
|
return new_response.content
|
|
|
|
|
|
+@upload_app.route('/backstage/multiupload/<path:iurl>', methods=['POST']) #collections
|
|
|
+def upload_multi_post(iurl):
|
|
|
+
|
|
|
+ # 取得md路徑
|
|
|
+ mdPath = ""
|
|
|
+ new_response = requests.get(PORTAL_SERVER + 'contents?url=' + iurl)
|
|
|
+ #my_dict = json.loads(new_response.content.decode('utf-8'))[0].items()
|
|
|
+ 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('\\', '/')
|
|
|
+ #print(mdPath)
|
|
|
+ mdPath = mdPath[0:mdPath.rfind('/')+1]
|
|
|
+ #print(mdPath)
|
|
|
+ isProduct = False
|
|
|
+ if mdPath.find("設計家具") >= 0 or mdPath.find("模組系統櫃") >= 0:
|
|
|
+ isProduct = True
|
|
|
+ #bdata = request.stream.read()
|
|
|
+ filepath = ""
|
|
|
+ itype = ""
|
|
|
+ print("markdown path is" + mdPath)
|
|
|
+ #aa = request.get_data()
|
|
|
+ if iurl == "title":
|
|
|
+ itype = iurl
|
|
|
+ filepath = iurl
|
|
|
+ else:
|
|
|
+ itype = iurl[0:iurl.find("/")]
|
|
|
+ filepath = iurl[iurl.rfind("/")+1:]
|
|
|
+
|
|
|
+ if request.method == 'POST':
|
|
|
+
|
|
|
+ # check if the post request has the file part
|
|
|
+ # print(request.full_path)
|
|
|
+ """ if 'file' not in request.files:
|
|
|
+ #flash('No file part')
|
|
|
+ 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 the user does not select a file, the browser submits an
|
|
|
+ # empty file without a filename.
|
|
|
+ """ if file.filename == '':
|
|
|
+ #flash('No selected file')
|
|
|
+ return redirect(request.url) """
|
|
|
+ oimgtype = file.filename[file.filename.rfind(".")+1:]
|
|
|
+ oimgtypeName = oimgtype
|
|
|
+ if oimgtype.lower() == 'jpg':
|
|
|
+ oimgtypeName = 'jpeg'
|
|
|
+
|
|
|
+ if file and not isProduct:
|
|
|
+ #filename = secure_filename(file.filename)
|
|
|
+
|
|
|
+ #fname = str(uuid.uuid4()) + file.filename[file.filename.rfind("."):]
|
|
|
+ #sitepath = UPLOAD_PATH_MAP[0][0] + filepath[filepath.rfind("/")+1:] + "/img/"
|
|
|
+ if filepath == "title":
|
|
|
+ sitepath = UPLOAD_PATH_MAP[0][2] + "/static/img/title/"
|
|
|
+ else:
|
|
|
+ sitepath = mdPath + "/img/"
|
|
|
+ #sitepath = UPLOAD_PATH_MAP[0][0] + "../" + itype + "/" + filepath + "/img/"
|
|
|
+
|
|
|
+ wfname = str(uuid.uuid4()).replace('-','') + ".webp"
|
|
|
+ owfname = wfname.replace('webp', oimgtype)
|
|
|
+ #fullpath = UPLOAD_PATH_MAP[0][0] + filepath[filepath.rfind("/")+1:] + "\\img\\" + fname
|
|
|
+ #print(UPLOAD_PATH_MAP[0][1] + filepath[filepath.rfind("/")+1:] + "/img/" + fname)
|
|
|
+ # file.save(fullpath)
|
|
|
+ #image_object = Image.open(fullpath)
|
|
|
+ #print(request.args.get('url', type=str))
|
|
|
+ wpath = os.getcwd() + "/backstage/upload/" + filepath+"/img/"
|
|
|
+ owpath = os.getcwd() + "/backstage/upload/" + filepath+"/img/orig/"
|
|
|
+ print("1wpath is " + wpath)
|
|
|
+ print("1owpath is " + owpath)
|
|
|
+ #fullpath = wpath + fname
|
|
|
+ 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)
|
|
|
+ # file.save(fullpath)
|
|
|
+ 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)
|
|
|
+ #file.save(os.getcwd()+ "/backstage/upload/img/"+ fname)
|
|
|
+ # return redirect(url_for('download_file', name=file.filename))
|
|
|
+ filelink += wfname + ";;;"
|
|
|
+ print(filelink)
|
|
|
+ aa = {"success": 1, "fileurl": filelink}
|
|
|
+ return aa
|
|
|
+
|
|
|
+ if request.method == 'GET':
|
|
|
+ print('GET')
|
|
|
+ # print(request.files)
|
|
|
+ # print(request.form)
|
|
|
+
|
|
|
+ # print(requests.post("/backstage/upload"))
|
|
|
+ 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']
|
|
|
+ #file2 = request.files['image2'] #again, reference
|
|
|
print("The file is at" + filepath)
|
|
|
|
|
|
# If the user does not select a file, the browser submits an
|
|
@@ -127,6 +243,7 @@ def upload_post(iurl):
|
|
|
print("Loc1a: " + wpath+wfname)
|
|
|
print("Loc1b: " + owpath+wfname)
|
|
|
print("Loc2: " + sitepath+wfname)
|
|
|
+ print(filepath)
|
|
|
#file.save(os.getcwd()+ "/backstage/upload/img/"+ fname)
|
|
|
# return redirect(url_for('download_file', name=file.filename))
|
|
|
aa = {"success": 1, "file": {"url": "/backstage/upload/" +
|