Search code examples
javascriptimagedownloadgoogle-street-view

Force Download Images with Javascript


I have a list of public links of Google streetview images similar to this

"https://maps.googleapis.com/maps/api/streetview?size=400x400&location=40.720032,-73.988354&fov=120&heading=120&pitch=20&key=AIzaSyC6UbcmFhZkX2q-3EyuHxl56e4zaF3L0y4"

I want to automate downloading of these image files to my computer using Javascript. Is there any Javascript library I can use for this task?


Solution

  • For a download link you can use a link with the "download" attribute (from here):

    <a href="https://maps.googleapis.com/maps/api/streetview?size=400x400&location=40.720032,-73.988354&fov=120&heading=120&pitch=20&key=AIzaSyC6UbcmFhZkX2q-3EyuHxl56e4zaF3L0y4" download>Download</a>
    

    For an automatic download you can use a script (from here):

    <script type="text/javascript">
        var link = document.createElement('a');
        link.href = 'https://maps.googleapis.com/maps/api/streetview?size=400x400&location=40.720032,-73.988354&fov=120&heading=120&pitch=20&key=AIzaSyC6UbcmFhZkX2q-3EyuHxl56e4zaF3L0y4';
        link.download = 'Download.jpg';
        document.body.appendChild(link);
        link.click();
    </script>