Home
Support Forums

[Urgent] Not able to download deployed code

I’m not able to download my deployed code. Previously it used to work but now after clicking download button nothing happens. It doesn’t give any response

Here how I used to download:
MySite > Deploys > Production(Published) > Download = On Clicking on download nothing happens.

Tried on safari, chrome, Mozilla as well as on mobile browsers but facing same issue. Please help it’s really urgent

Hi @Tabrez
This is a known issue as per

It seems there are lot of files something above 6000. So your support staff informed me on mail that I can download it using API. Can you help me understanding or by redirecting to some api which I can use to download the code.

Full Netlify API documentation is here and unless things have changed there is no single API call to download a deploy as per this post.

I have been trying to draft a tool to help users download their deploy, but I’m unable to find a correct tool to download the files. I’ve found aria2c but the way I’ve implemented it works only on Windows.

DISCLAIMER: THIS IS NOT AN OFFICIAL TOOL BY NETLIFY.

Nevertheless, here’s what you can do. Copy the following code and save it as index.js:

const FS = require('fs')
const Chalk = require('chalk')
const Fetch = require('node-fetch')
const Inquirer = require('inquirer')
const NetlifyAPI = require('netlify')
const ByteSize = require('byte-size')
const Pluralize = require('pluralize')
const Exec = require('child_process').execFile

const authToken = 'token'
const netlifyAuth = new NetlifyAPI(authToken)
const byteSizeOptions = {
  units: 'iec',
  precision: 2
}

netlifyAuth.listSites().then(sites => {

  console.log(Chalk.yellow('Fetching all websites...'))

  const siteList = []

  sites.forEach(site => {

    siteList.push({
      value: site.id,
      name: site.name
    })

  })

  Inquirer.prompt([{
    loop: false,
    name: 'site',
    type: 'list',
    pageSize: 10,
    choices: siteList,
    message: 'Choose a website:'
  }]).then(answer => {

    const siteName = siteList.filter(site => {
      return site.value === answer.site
    })

    netlifyAuth.listSiteDeploys({
      site_id: answer.site
    }).then(deploys => {

      console.log(Chalk.yellow('Fetching all successful deploys for the selected website...'))

      const deploysList = []

      deploys.forEach(deploy => {

        if (deploy.state != 'error' && !deploy.skipped) {

          deploysList.push({
            value: deploy.id,
            name: deploy.title
          })

        }

      })

      Inquirer.prompt([{
        loop: false,
        type: 'list',
        pageSize: 10,
        name: 'deploy',
        choices: deploysList,
        message: 'Choose a deploy:'
      }]).then(answer => {

        console.log(Chalk.yellow('Fetching all files for the selected deploy...'))

        const deployID = answer.deploy

        Fetch(`https://api.netlify.com/api/v1/deploys/${deployID}/files`, {
          headers: {
            Authorization: `Bearer ${authToken}`
          }
        }).then(response => response.json()).then(files => {

          let deploySize = 0
          const downloadableFiles = []

          let baseMarkup = `<!doctype html><html lang=en><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1.0"><title>Deploy details for #${deployID}</title><style>*{font-family:sans-serif}table{border:1px solid black}table *{padding:5px}td:first-child,td:last-child{text-align:right}th:nth-child(2),td:nth-child(2){border:1px solid black;border-top:0;border-bottom:0}</style></head><body><p>View the <a href="https://app.netlify.com/sites/${siteName[0].name}/deploys/${deployID}/" target="_blank" rel="nofollow noopener noreferrer">deploy log</a>.</p><table><thead><tr><th>#</th><th>Path</th><th>Size</th></tr></thead><tbody>`

          files.forEach(file => {

            if (file.path != ('/netlify.toml' || '/_redirects' || '/_headers')) {
              downloadableFiles.push(file)
            }

          })

          downloadableFiles.forEach((file, index) => {
            deploySize += file.size
            baseMarkup += `<tr><td>${index + 1}</td><td><a href="https://${deployID}--${siteName[0].name}.netlify.app${file.path}" target="_blank" rel="nofollow noopener noreferrer">${file.path}</a></td><td>${ByteSize(file.size, byteSizeOptions)}</td></tr>`
          })

          baseMarkup += `</tbody></table><p>The deploy contains ${Pluralize('files', downloadableFiles.length, true)} amounting to ~${ByteSize(deploySize, byteSizeOptions)}</p></body></html>`

          FS.writeFileSync('./index.html', baseMarkup)

          console.log(Chalk.green('File list saved as ./index.html.'))

          Inquirer.prompt([{
            type: 'confirm',
            name: 'confirm',
            message: `Are you sure you wish to download the deploy? ${Chalk.red(`It will cost you ~${ByteSize(deploySize, byteSizeOptions)} of your Netlify bandwidth!`)}`
          }]).then(answer => {

            if (answer.confirm) {

              const downloadList = FS.createWriteStream('./files.txt')

              downloadableFiles.forEach(file => {
                downloadList.write(`https://${deployID}--${siteName[0].name}.netlify.app${file.path}\n\tdir=./download${file.path.substring(0, file.path.lastIndexOf('/') + 1).slice(0, -1)}\n`)
              })

              downloadList.end()

              if (process.platform === 'win32') {

                const downloader = Exec('./node_modules/aria2c-test-1/aria2c-win32.exe', ['-i', './files.txt', '--auto-file-renaming=false'])

                downloader.stdout.on('data', data => {
                  console.log(data)
                })

              }

            } else {
              console.log(Chalk.green('Okay. Exiting...'))
            }

          })

        })

      })

    })

  })

})

You’ve to replace const authToken = 'token' with your Personal Access Token there: Netlify App.

Then, run npm i aria2c-test-1 byte-size chalk inquirer netlify node-fetch pluralize && node index.js and follow the terminal.

For macOS and Linux users, this code still generates an index.html that contains a list of all files in the deploy. You can then download the ones required individually or use some external download tool that can process HTML files.

NOTE: DOWNLOADING FILES VIA THIS TOOL WILL COST YOU YOUR NETLIFY ACCOUNT’S BANDWIDTH.

If someone has any ideas to improve this, it’s more than welcome.

2 Likes

Also, while there’s a issue as @coelmay suggested above, it might/might not be true for this case. As I already told them, their deploy seems huge to download. While I haven’t checked the deploy’s file size in total, the deploy does have over 6k files, 6822 to be exact. Thus, we would never recommend downloading such a big deploy using the UI.

However, if a deploy of similar size was working before and it’s not working now, then it might indicate a relation with the problem that has been linked.

2 Likes