Skip to content

Instantly share code, notes, and snippets.

@ridem
Last active October 28, 2023 12:15
Show Gist options
  • Save ridem/1dc8dd62dd81e736aade31d98b3459b0 to your computer and use it in GitHub Desktop.
Save ridem/1dc8dd62dd81e736aade31d98b3459b0 to your computer and use it in GitHub Desktop.
Download all Shopify CDN assets from a store
function fetchPageAssets(){
var downloader = $("<a id='download-file' href='' download=''></a>")
$(".ui-title-bar").append(downloader)
var assets = $("#assets-table .next-input--readonly")
assets.each(function(index, input) {
$('#download-file').attr('href', input.value);
$('#download-file')[0].click();
if (index + 1 == assets.length) {
var lastItem = $(input).parents("tr[bind-class]").attr('bind-class').substring(25,36)
$.ajax({
url: "/admin/settings/files?direction=next&last_id="+lastItem+"&last_value="+ lastItem+"&limit=100&order=id+desc",
}).done(function(data) {
var mutationObserver = new MutationObserver(function(mutations, observer) {
mutations.forEach(function(mutation) {
if (mutation.target.id && mutation.target.id == "assets-table") {
fetchPageAssets()
observer.disconnect()
}
})
});
mutationObserver.observe(document, {
childList: true,
subtree: true
});
var newDoc = document.open("text/html", "replace");
newDoc.write(data);
newDoc.close();
})
}
})
}
fetchPageAssets()
function fetchPageAssets() {
var assets = $("#assets-table .next-input--readonly")
assets.each(function (index, input) {
files.push(input.value)
if (index + 1 == assets.length) {
var lastItem = $(input).parents("tr[bind-class]").attr('bind-class').substring(25, 36)
$.ajax({
url: "/admin/settings/files?direction=next&last_id=" + lastItem + "&last_value=" + lastItem + "&limit=100&order=id+desc",
}).done(function (data) {
var mutationObserver = new MutationObserver(function (mutations, observer) {
mutations.some(function (mutation) {
if (mutation.target.id &&
mutation.target.id == "assets-area" &&
mutation.addedNodes[0].nextElementSibling.innerHTML.indexOf("empty") > -1
) {
downloadListFile()
observer.disconnect()
return true;
} else if (mutation.target.id &&
mutation.target.id == "assets-area" &&
mutation.previousSibling.className == "ui-layout ui-layout--full-width"
) {
fetchPageAssets()
observer.disconnect()
return true;
}
})
});
mutationObserver.observe(document, {
childList: true,
subtree: true
});
var newDoc = document.open("text/html", "replace");
newDoc.write(data);
newDoc.close();
})
}
})
}
function downloadListFile() {
var downloader = $("<a id='download-file' href='' download='shopify-files.txt'></a>")
$(".ui-title-bar").append(downloader)
var data = 'data:application/octet-stream;base64,' + window.btoa(files.join(','));
$('#download-file').attr('href', data);
$('#download-file')[0].click();
}
var files = []
fetchPageAssets()

Instructions

  1. Go to your Shopify admin/settings/files page
  2. Open your browser Dev tools, go to the console

Then, depending on the option you choose:

Option 1 - Download all the files directly (might crash you browser)

  1. Make sure your browser is set to download files automatically and doesn't ask for the download location every time
  2. Paste the content of the console_download_files.js file, and press enter
  3. Your browser will automatically fetch each page and download every file on it. It might ask you to accept "multiple downloads" (Chrome)

Option 2 - Download a .txt file containing the list of the files to download

  1. Paste the content of the console_download_list.js file, and press enter
  2. Your browser will automatically fetch each page and download the list of all the files on the CDN. You'll then be able to use any file download manager to import the list and safely download everything.
@jaimish11
Copy link

Another way to ensure the files downloaded are .PNG rather than .WEBP is by using Chrome as your default browser. Chrome will automatically convert the files for you.

@alemens
Copy link

alemens commented Dec 21, 2020

for those who get 404 error, you can take a look here: https://gist.github.com/lexthor/63ac60fe5bce357084a934503c677233
I have forked the gist and update the code.

Thanks @lexthor

@molotow11
Copy link

This working for me in 2021
`
/**

  • Script for put into console for download all images from Shopify /admin/settings/files?limit=250
    */

function fetchPageAssets() {
let images = document.querySelectorAll('img[src*=files]');
images.forEach(function(image) {
files.push('<a href="' + image.src.replace(/_60x60/, "") + '"><img src="' + image.src.replace(/_60x60/, "") + '">
');
});
}

function downloadListFile() {
let button = document.createElement("a");
let data = 'data:application/octet-stream;base64,' + window.btoa(files.join('\n'));
button.id = "download-file";
button.href = data;
button.download = "shopify-files.html";
document.querySelector("body").append(button);
button.click();
}

var files = []
files.push('\n')
fetchPageAssets()
files.push('\n\n')
downloadListFile()
`

@reajkee13
Copy link

reajkee13 commented Jun 2, 2021

This working for me in 02.06.2021 after shopify admin panel updates!

function fetchPageAssets() {
let images = document.querySelectorAll('img[src*=files]');
images.forEach(function(image) {
files.push('<img src="' + image.src.replace(/_60x60/, "") + '">');
});
}

function downloadListFile() {
let button = document.createElement("a");
let data = 'data:application/octet-stream;base64,' + window.btoa(files.join('\n'));
button.id = "download-file";
button.href = data;
button.download = "shopify-files.html";
document.querySelector("body").append(button);
button.click();
}
var files = []
files.push('\n')
fetchPageAssets()
files.push('\n\n')
downloadListFile()

@ryanhilton
Copy link

Thank you @reajkee13!

@oxr463
Copy link

oxr463 commented Jul 13, 2021

This working for me in 02.06.2021 after shopify admin panel updates!

function fetchPageAssets() {
let images = document.querySelectorAll('img[src*=files]');
images.forEach(function(image) {
files.push('<img src="' + image.src.replace(/_60x60/, "") + '">');
});
}

function downloadListFile() {
let button = document.createElement("a");
let data = 'data:application/octet-stream;base64,' + window.btoa(files.join('\n'));
button.id = "download-file";
button.href = data;
button.download = "shopify-files.html";
document.querySelector("body").append(button);
button.click();
}
var files = []
files.push('\n')
fetchPageAssets()
files.push('\n\n')
downloadListFile()

Perfect!

@DainaRozenberga
Copy link

Hello, can anybody help here!
I got to download all files from Shopify, they all are in one HTML file, can't convert to 250 different jpg files. How could I do this? None of the online converters doesn't read those files...

Another option would be to upload the same HTML files to other Shopify stores, already as those 250 photos.

THANKS, A MILLION!

@molotow11
Copy link

Hello, can anybody help here!
I got to download all files from Shopify, they all are in one HTML file, can't convert to 250 different jpg files. How could I do this? None of the online converters doesn't read those files...

Another option would be to upload the same HTML files to other Shopify stores, already as those 250 photos.

THANKS, A MILLION!

You can save then this page with your browser and all files will be in a separate folder.

@DainaRozenberga
Copy link

SO LOVELY! THANK YOU!

@QuantumDevQBL
Copy link

Thank you so much @reajkee13 :-)

@carolinerusso
Copy link

Amazing, thank you!

@gabepetersen
Copy link

Thanks a ton!

@stephkennerson
Copy link

Thanks @reajkee13, worked for me today!

@storefixco
Copy link

Thank you @reajkee13

@Nadeemp77
Copy link

Worked for me also...thank you for this script..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment