Browse Source

210703 update for backend upload
with copied-image and drag-n-drop image file

yukyo 3 years ago
parent
commit
edff623884
1 changed files with 11 additions and 6 deletions
  1. 11 6
      backstage/upload/routes.py

+ 11 - 6
backstage/upload/routes.py

@@ -19,32 +19,37 @@ def upload_post():
     #bdata = request.stream.read()
     #aa = request.get_data()
     if request.method == 'POST':
-        print(request.method)
+        
         # check if the post request has the file part
         #print(request.files)
         """ if 'file' not in request.files:
             #flash('No file part')
             return redirect(request.url) """
+        
+        #print(request.get_data())
         file = request.files['image']
+        
         # 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) """
+        
         if file:
             #filename = secure_filename(file.filename)
-            #print(os.getcwd().)
-            file.save(os.getcwd()+ "/backstage/upload/img/"+ file.filename)
+            #print('1')
+            fname = str(uuid.uuid4()) + file.filename[file.filename.rfind("."):]
+            file.save(os.getcwd()+ "/backstage/upload/img/"+ fname)
             #return redirect(url_for('download_file', name=file.filename))    
-            aa = {"success" : 1,"file": { "url" : "/backstage/upload/"+ file.filename, } }
+            aa = {"success" : 1,"file": { "url" : "/backstage/upload/"+ fname, } }
             return aa
     if request.method == 'GET':
-        print(request.method)
+        print('GET')
         #print(request.files)
         #print(request.form)
     
     #print(requests.post("/backstage/upload"))
-    aa = {"success" : 1,"file": { "url" : "https://www.tesla.com/tesla_theme/assets/img/_vehicle_redesign/roadster_and_semi/roadster/hero.jpg", } }
+    aa = {"success" : 1,"file": { "url" : "http://www.choozmo.com/images/logo%20%281%29.webp", } }
     return aa
 
 @upload_app.route('/backstage/upload/<filename>', methods=['GET'])