Python Forum
Download multiple images with one click
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  download with internet download manager coral_raha 0 2,883 Jul-18-2021, 03:11 PM
Last Post: coral_raha
  Scripting: Multiple Votes With a Single Click or Button Ovidiu 0 1,365 Jul-07-2020, 10:51 AM
Last Post: Ovidiu
  Running Ajax multiple times on button click? CaptainCsaba 1 2,072 Mar-11-2020, 02:17 PM
Last Post: CaptainCsaba
  naming images adding to number within multiple functions Bmart6969 0 1,894 Oct-09-2019, 10:11 PM
Last Post: Bmart6969
  Download multiple large json files at once halcynthis 0 2,752 Feb-14-2019, 08:41 AM
Last Post: halcynthis
  Pasting multiple images on to one image with a for loop. DreamingInsanity 2 6,416 Feb-01-2019, 12:39 PM
Last Post: DreamingInsanity
  Download multiple images and rename them andie31 4 5,035 Sep-13-2018, 10:26 AM
Last Post: andie31

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020