cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Download dropbox images to Netlify build folder

Download dropbox images to Netlify build folder

itsjustmyron
Explorer | Level 3
Go to solution

I'm trying to retrieve images from my dropbox folder into my Jekyll build on Netlify, but the images are unreadable with the following code. I think that I'm using the wrong conversion for the contents.

dbx
  .filesListFolder({ path: "/images" })
  .then(response => {
    response.entries.forEach(entry => {
      const { name, path_lower } = entry;

      if (entry[".tag"] === "file") {
        dbx
          .filesDownload({ path: path_lower })
          .then(data => {
            const filename = path.resolve(IMAGES_DIR, name);
            const filecontents = data.fileBinary.toString("base64");

            fs.outputFile(filename, filecontents).catch(error => {
              if (error) {
                return console.log("Error: file failed to write", name, error);
              }
            });
          })
          .catch(error => {
            console.log("Error: file failed to download", name, error);
          });
      }
    });
  })

Any help will be much appreciated. Thanks.

1 Accepted Solution

Accepted Solutions
1 Reply 1

Greg-DB
Dropbox Staff
Go to solution
Need more support?