DEV Community

Fabian Anguiano
Fabian Anguiano

Posted on

How to run a internal Flask APK Server

Flask APK Server

Overview

This Flask application serves an APK file to clients. Developed as a minimalistic solution, the app is designed to be used in a controlled environment with a limited number of users.

Features:

  • Simple endpoint (/apk) to download the APK.
  • Endpoint (/test) to test the server's functionality.
  • Endpoint (/apk-test) to check the presence and size of the APK file.

Flask App:


python
from flask import Flask, send_file
import os

app = Flask(__name__)

@app.route('/apk')
def download_apk():
    apk_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'app.apk')
    return send_file(apk_path, as_attachment=True, download_name='app.apk')

@app.route('/apk-test')
def test_apk():
    apk_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'app.apk')
    try:
        size = os.path.getsize(apk_path)
        return jsonify(status="success", message=f"The APK exists and its size is {size} bytes")
    except OSError:
        return jsonify(status="error", message="The APK does not exist or there's a problem accessing it.")

@app.route('/test')
def test_route():
    return "Test route is working!"

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=2000, debug=True)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Agent.ai Challenge image

Congrats to the Agent.ai Challenge Winners 🏆

The wait is over! We are excited to announce the winners of the Agent.ai Challenge.

From meal planners to fundraising automators to comprehensive stock analysts, our team of judges hung out with a lot of agents and had a lot to deliberate over. There were so many creative and innovative submissions, it is always so difficult to select our winners.

Read more →

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay