Return server.log file on server using Flask [duplicate]












0















This question already has an answer here:




  • How to serve static files in Flask

    13 answers



  • Display the contents of a log file as it is updated

    2 answers




I am using python 3 and flask server. This server can browse a file and upload it to a folder called 'uploads'



After all processing the result is saved to 'server.log'



I want to display result to android app. For that, I want to return server.log to server so it can be accessed by an android app.



Any kind of help is appreciated. Thanks in advance.



Here is the code:



import os
from flask import Flask, request, redirect, url_for, send_from_directory, jsonify
from werkzeug import secure_filename

UPLOAD_FOLDER = 'uploads'
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'mp4'])

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

def allowed_file(filename):
# this has changed from the original example because the original did not work for me
return filename[-3:].lower() in ALLOWED_EXTENSIONS

@app.route('/', methods=['GET', 'POST'])
def upload_file():
print("Printing the request {}".format(request.headers))
print("Printing the request {}".format(request))
print("Printing the request {}".format(request.data))
print("Printing the request {}".format(request.form))
if request.method == 'POST':
file = request.files['file']
if file and allowed_file(file.filename):
print('**found file', file.filename)
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
# for browser, add 'redirect' function on top of 'url_for'
return jsonify({"success" : url_for('uploaded_file',
filename=filename)})
return '''
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file>
<input type=submit value=Upload>
</form>
'''

@app.route('/uploads/<filename>') #this part of server.py is missing from video attendance output.py
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)

if __name__ == '__main__':
app.run(host= '192.168.0.102', debug=True)









share|improve this question













marked as duplicate by davidism flask
Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 14:39


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




















    0















    This question already has an answer here:




    • How to serve static files in Flask

      13 answers



    • Display the contents of a log file as it is updated

      2 answers




    I am using python 3 and flask server. This server can browse a file and upload it to a folder called 'uploads'



    After all processing the result is saved to 'server.log'



    I want to display result to android app. For that, I want to return server.log to server so it can be accessed by an android app.



    Any kind of help is appreciated. Thanks in advance.



    Here is the code:



    import os
    from flask import Flask, request, redirect, url_for, send_from_directory, jsonify
    from werkzeug import secure_filename

    UPLOAD_FOLDER = 'uploads'
    ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'mp4'])

    app = Flask(__name__)
    app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

    def allowed_file(filename):
    # this has changed from the original example because the original did not work for me
    return filename[-3:].lower() in ALLOWED_EXTENSIONS

    @app.route('/', methods=['GET', 'POST'])
    def upload_file():
    print("Printing the request {}".format(request.headers))
    print("Printing the request {}".format(request))
    print("Printing the request {}".format(request.data))
    print("Printing the request {}".format(request.form))
    if request.method == 'POST':
    file = request.files['file']
    if file and allowed_file(file.filename):
    print('**found file', file.filename)
    filename = secure_filename(file.filename)
    file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
    # for browser, add 'redirect' function on top of 'url_for'
    return jsonify({"success" : url_for('uploaded_file',
    filename=filename)})
    return '''
    <!doctype html>
    <title>Upload new File</title>
    <h1>Upload new File</h1>
    <form action="" method=post enctype=multipart/form-data>
    <p><input type=file name=file>
    <input type=submit value=Upload>
    </form>
    '''

    @app.route('/uploads/<filename>') #this part of server.py is missing from video attendance output.py
    def uploaded_file(filename):
    return send_from_directory(app.config['UPLOAD_FOLDER'], filename)

    if __name__ == '__main__':
    app.run(host= '192.168.0.102', debug=True)









    share|improve this question













    marked as duplicate by davidism flask
    Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 23 '18 at 14:39


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















      0












      0








      0








      This question already has an answer here:




      • How to serve static files in Flask

        13 answers



      • Display the contents of a log file as it is updated

        2 answers




      I am using python 3 and flask server. This server can browse a file and upload it to a folder called 'uploads'



      After all processing the result is saved to 'server.log'



      I want to display result to android app. For that, I want to return server.log to server so it can be accessed by an android app.



      Any kind of help is appreciated. Thanks in advance.



      Here is the code:



      import os
      from flask import Flask, request, redirect, url_for, send_from_directory, jsonify
      from werkzeug import secure_filename

      UPLOAD_FOLDER = 'uploads'
      ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'mp4'])

      app = Flask(__name__)
      app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

      def allowed_file(filename):
      # this has changed from the original example because the original did not work for me
      return filename[-3:].lower() in ALLOWED_EXTENSIONS

      @app.route('/', methods=['GET', 'POST'])
      def upload_file():
      print("Printing the request {}".format(request.headers))
      print("Printing the request {}".format(request))
      print("Printing the request {}".format(request.data))
      print("Printing the request {}".format(request.form))
      if request.method == 'POST':
      file = request.files['file']
      if file and allowed_file(file.filename):
      print('**found file', file.filename)
      filename = secure_filename(file.filename)
      file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
      # for browser, add 'redirect' function on top of 'url_for'
      return jsonify({"success" : url_for('uploaded_file',
      filename=filename)})
      return '''
      <!doctype html>
      <title>Upload new File</title>
      <h1>Upload new File</h1>
      <form action="" method=post enctype=multipart/form-data>
      <p><input type=file name=file>
      <input type=submit value=Upload>
      </form>
      '''

      @app.route('/uploads/<filename>') #this part of server.py is missing from video attendance output.py
      def uploaded_file(filename):
      return send_from_directory(app.config['UPLOAD_FOLDER'], filename)

      if __name__ == '__main__':
      app.run(host= '192.168.0.102', debug=True)









      share|improve this question














      This question already has an answer here:




      • How to serve static files in Flask

        13 answers



      • Display the contents of a log file as it is updated

        2 answers




      I am using python 3 and flask server. This server can browse a file and upload it to a folder called 'uploads'



      After all processing the result is saved to 'server.log'



      I want to display result to android app. For that, I want to return server.log to server so it can be accessed by an android app.



      Any kind of help is appreciated. Thanks in advance.



      Here is the code:



      import os
      from flask import Flask, request, redirect, url_for, send_from_directory, jsonify
      from werkzeug import secure_filename

      UPLOAD_FOLDER = 'uploads'
      ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'mp4'])

      app = Flask(__name__)
      app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

      def allowed_file(filename):
      # this has changed from the original example because the original did not work for me
      return filename[-3:].lower() in ALLOWED_EXTENSIONS

      @app.route('/', methods=['GET', 'POST'])
      def upload_file():
      print("Printing the request {}".format(request.headers))
      print("Printing the request {}".format(request))
      print("Printing the request {}".format(request.data))
      print("Printing the request {}".format(request.form))
      if request.method == 'POST':
      file = request.files['file']
      if file and allowed_file(file.filename):
      print('**found file', file.filename)
      filename = secure_filename(file.filename)
      file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
      # for browser, add 'redirect' function on top of 'url_for'
      return jsonify({"success" : url_for('uploaded_file',
      filename=filename)})
      return '''
      <!doctype html>
      <title>Upload new File</title>
      <h1>Upload new File</h1>
      <form action="" method=post enctype=multipart/form-data>
      <p><input type=file name=file>
      <input type=submit value=Upload>
      </form>
      '''

      @app.route('/uploads/<filename>') #this part of server.py is missing from video attendance output.py
      def uploaded_file(filename):
      return send_from_directory(app.config['UPLOAD_FOLDER'], filename)

      if __name__ == '__main__':
      app.run(host= '192.168.0.102', debug=True)




      This question already has an answer here:




      • How to serve static files in Flask

        13 answers



      • Display the contents of a log file as it is updated

        2 answers








      python-3.x flask






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 6:06









      Afshan Anwarali

      224




      224




      marked as duplicate by davidism flask
      Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 23 '18 at 14:39


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by davidism flask
      Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 23 '18 at 14:39


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          0






          active

          oldest

          votes

















          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes

          Popular posts from this blog

          What visual should I use to simply compare current year value vs last year in Power BI desktop

          Alexandru Averescu

          Trompette piccolo