Python Forum

Full Version: Download multiple images with one click
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys, I've solve my last problem with help from @perfringo ! (https://python-forum.io/Thread-Download-...7#pid57947)

Now I've got into another problem. How do I download multiple images with just one click ? In html. I'm creating a web app based on flask.

So my run.py file is looking like this :

from flask import Flask, jsonify, render_template, request
app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/generate', methods=['GET'])
def generate():
    prefix = request.args.get('prefix')
    urls = []
    for number in range(1, 7):
        urls.append('https://example.com/{p}-{n}.jpg'.format(p=prefix, n=number))
    return jsonify(result=urls)
and my index.html is looking like this :

<!doctype html>
<html lang="en">
<html>
<head>
<title>Image Grabber v1.0</title>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
</head>
<body>
<center>
<script type=text/javascript>
$SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
$( document ).ready(function() {
$('#download').bind('click', function() {
$.getJSON($SCRIPT_ROOT + '/generate', {
prefix: $('input[name="prefix"]').val()
}, function(data) {
$("#result").text(data.result);
});
return false;
});
});
</script><br>
<h2>Image Grabber v1.0</h2>
<p><input type=text size=45 name=prefix>
<span id=result></span>
<p><button type="submit" id=download>Download</button></p>
</center>
</body>
</html>


So the user will input a code, and the form will generate 6 urls. Now I have no idea how to download them all using Javascript and jquery or something else. Any help is appreciated.