I am developing an android app with Python Flask.I am need to transfer image links from server to android.How is that possible?I read about static folder but i think this is not the best solution. On apache you can simply write: /images/image.jpg and the server will give you the image.Is it possible in flask too?
            Asked
            
        
        
            Active
            
        
            Viewed 523 times
        
    1 Answers
0
            
            
        Using a static folder is the correct way of doing it.
First, you need to provide a route:
app = Flask(__name__, static_url_path='')
app.config['HOME_FOLDER'] = os.path.dirname(os.path.abspath(__file__))
@app.route('/public/<path>')
def downloadFile(path):
    resp = send_from_directory(app.config['HOME_FOLDER'], path, as_attachment=True)
    return resp
And then the folder structure would be as follows:
/static
    |-file1
    |-file2
Finally, to create the link to those files, in javascript you would have:
var file_path = 'file1';
var a = document.createElement('A');
a.href = file_path;
a.download = file_path.substr(file_path.lastIndexOf('/') + 1);
document.body.appendChild(a);
 
    
    
        mray190
        
- 496
- 3
- 13
