Bottom Page

Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Download multiple images with one click
#1
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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  naming images adding to number within multiple functions Bmart6969 0 112 Oct-09-2019, 10:11 PM
Last Post: Bmart6969
  Download multiple large json files at once halcynthis 0 362 Feb-14-2019, 08:41 AM
Last Post: halcynthis
  Pasting multiple images on to one image with a for loop. DreamingInsanity 2 361 Feb-01-2019, 12:39 PM
Last Post: DreamingInsanity
  Download multiple images and rename them andie31 4 866 Sep-13-2018, 10:26 AM
Last Post: andie31

Forum Jump:


Users browsing this thread: 1 Guest(s)