简体   繁体   English

将 Dropbox 图像下载到 Netlify 构建文件夹

[英]Download dropbox images to Netlify build folder

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.我正在尝试将我的 Dropbox 文件夹中的图像检索到我在 Netlify 上构建的 Jekyll 中,但是使用以下代码无法读取这些图像。 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.谢谢。

Fixed by changing通过更改修复

const filecontents = data.fileBinary.toString("base64");

to

const filecontents = data.fileBinary;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM