Sep-26-2018, 01:24 PM
Hello! I'm trying to create a simple REST API application that would show the contents of some folder on the server.
I run my server through the console, then go to the browser, write the address http://localhost:5000/api/listdir and everything works well. But how to make it so that any user on the Internet can see the contents of this folder and not only the localhost? What address should I enter in browser from other computer? Is this possible with Python and Flask?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import os from flask import Flask, jsonify app = Flask(__name__) files_in_dirs = [] @app .route( '/api/listdir' , methods = [ 'GET' ]) def list_dir(): path = '/home/user/media' for dirname, dirnames, filenames in os.walk(path): # print path to all filenames for filename in filenames: files_in_dirs.append(os.path.join(dirname, filename)) return jsonify({ 'Files on the server: ' : files_in_dirs}) if __name__ = = '__main__' : app.run(debug = True ) |