Guest User

Untitled

a guest
Jun 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. @app.route('/')
  2. def dir_listing(file_Idx=0):
  3.  
  4. # Return 404 if path doesn't exist
  5. if not os.path.exists(DOWNLOAD_FOLDER):
  6. print("PATH IS NONEXISTENCT!!!!")
  7. return abort(404)
  8.  
  9. # Show directory contents
  10. files = os.listdir(DOWNLOAD_FOLDER)
  11. filePath = os.path.join(DOWNLOAD_FOLDER, files[file_Idx])
  12.  
  13. return render_template('files.html', file=filePath, file_Idx=file_Idx)
  14.  
  15. @app.route('/', methods=['GET', 'POST'])
  16. def upload_file(file_Idx=0, label1 = 'someLabel', label2 = 'someLabel2'):
  17. print(request.files) #returns as empty dict
  18. if request.method == 'POST' or request.method == 'GET':
  19. if 'file' not in request.files:
  20. #Jumps in here every time
  21. return redirect(request.url)
  22. #... to be implemented to move file to correct location
  23. return redirect(url_for('dir_listing', file_Idx=file_Idx))
  24.  
  25. <body>
  26. <form method=post>
  27. <img id=fileId type=file name=file width="200" height="200" src="{{ file }}"/>
  28. <input type=submit value=Upload>
  29. </form>
  30. </body>
Add Comment
Please, Sign In to add comment