简体   繁体   English

由于对目录的非法操作,带有 node-s3-client 的 DownloadDir 失败

[英]DownloadDir with node-s3-client failing due to illegal operation on a directory

I am using a node s3 client ( https://github.com/andrewrk/node-s3-client#clientdownloaddirparams ) to sync an entire directory from S3 to a local directory.我正在使用节点 s3 客户端( https://github.com/andrewrk/node-s3-client#clientdownloaddirparams )将整个目录从 S3 同步到本地目录。

As per the documentation, my code is as follows:根据文档,我的代码如下:

    var s3 = require('s3');     
    var client = s3.createClient({
        s3Options: {
            accessKeyId: Config.accessKeyId,
            secretAccessKey: Config.secretAccessKey
        }
    });

    var downloader = client.downloadDir({
        localDir: 'images/assets',
        deleteRemoved: true,
        s3Params: {
            Bucket: Config.bucket,
            Prefix: Config.bucketFolder
        }
    });

    downloader.on('error', function(err) {
        console.error("unable to download: ", err);
    });

    downloader.on('progress', function() {
        console.log("progress", downloader.progressMd5Amount, downloader.progressAmount, downloader.progressTotal);
    });

    downloader.on('end', function(data) {
        console.log("done downloading", data);
    });

This begins syncing and the folder begins downloading, but eventually returns this:这开始同步,文件夹开始下载,但最终返回:

progress 0 0 0
...
progress 1740297 225583 5150000
unable to download:  { Error: EISDIR: illegal operation on a directory, open 'images/assets'
    at Error (native)
  errno: -21,
  code: 'EISDIR',
  syscall: 'open',
  path: 'images/assets' }

The directory does indeed exist.该目录确实存在。 I've tried moving directory location, path, etc, but nothing seems to do the trick.我试过移动目录位置、路径等,但似乎没有任何作用。 I have researched this error and have found out that it occurs when you try to open a file, but the path given is a directory.我研究了这个错误,发现它是在你尝试打开一个文件时发生的,但给出的路径是一个目录。 Not sure why this s3-client is trying to open a file instead of a directory.不知道为什么这个 s3-client 试图打开一个文件而不是一个目录。 Any help or advice would be awesome.任何帮助或建议都会很棒。 Thanks!谢谢!

Remember that in S3, you can create a directory that has the same name as a file. 请记住,在S3中,您可以创建一个与文件同名的目录。 Based on the error you're getting, I would say that in S3 you have a file named images and a folder named images. 基于您得到的错误,我想说在S3中您有一个名为images的文件和一个名为images的文件夹。 This would be illegal on the file system but not in S3. 这在文件系统上将是非法的,但在S3中则不合法。

I just determined that download speeds were causing this issue. 我只是确定下载速度导致了此问题。 Unfortunately, I was on a network with .5 up and down. 不幸的是,我所在的网络上下有0.5。 I just switched over to 25/10 and its working fine. 我刚刚切换到25/10,并且工作正常。

Use getS3Params function to resolve this :使用 getS3Params 函数来解决这个问题:

getS3Params: function getS3Params(localFile, s3Object, callback) {
    if (path.extname(localFile) === '') {  callback(null, null); }
    else { callback(null, {}); }
}

https://github.com/andrewrk/node-s3-client/issues/80 https://github.com/andrewrk/node-s3-client/issues/80

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

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