Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Dropbox JS mass writeFile未写入所有文件_Javascript_Node.js_Dropbox_Dropbox Api - Fatal编程技术网

Javascript Dropbox JS mass writeFile未写入所有文件

Javascript Dropbox JS mass writeFile未写入所有文件,javascript,node.js,dropbox,dropbox-api,Javascript,Node.js,Dropbox,Dropbox Api,我有这段代码,它应该在某个目录的每个子目录中运行文件,在我的Dropbox中创建相同的目录(具有相同的路径),然后将文件上载到我的Dropbox中的那个目录。我正在使用插件 问题是,为了上传文件,我必须运行脚本多次(30多次以上)才能上传大部分文件。但即便如此,仍有一些文件无法上传 这就是我得到的错误。有时当我运行脚本时没有错误,但下一次会有错误。即使没有错误,所有的文件都不在那里。如果可能的话,我想阻止这件事发生 POST中的Dropbox API错误503https://api-conten

我有这段代码,它应该在某个目录的每个子目录中运行文件,在我的Dropbox中创建相同的目录(具有相同的路径),然后将文件上载到我的Dropbox中的那个目录。我正在使用插件

问题是,为了上传文件,我必须运行脚本多次(30多次以上)才能上传大部分文件。但即便如此,仍有一些文件无法上传

这就是我得到的错误。有时当我运行脚本时没有错误,但下一次会有错误。即使没有错误,所有的文件都不在那里。如果可能的话,我想阻止这件事发生

POST中的Dropbox API错误503https://api-content.dropbox.com/1/files_put/auto/dropbox/path/for/file/here.css :{“错误”:“未能获取871742009的锁,请重新发出请求。”}


有什么不同的方法可以让所有文件一次上载?

由于您启动了大量并行上载,因此发生了错误。有些请求之所以成功,是因为它们在服务器上排队并被阻止,但如果您发送的并发请求多于几个,则很可能有些请求在等待轮到它们时超时

您需要按顺序进行上载,一次上载一个(或至少一次上载一小部分),以避免此类错误

编辑:您想要的代码可能是这样的。(我根本没有测试过。)我调用了
mkdir
,因为目录是在Dropbox中隐式创建的,但重要的变化是调用
next()
的位置。(我假设了
walker
的工作原理,但我不知道它是如何工作的。如果这仍然不起作用,您可能需要在调用
writeFile
时记录一些内容,以查看何时调用它。)


您能分享一下您遇到的错误吗?我尝试使用setTimeout()在1次之后将脚本暂停15秒,但没有成功。我在不到5秒内看到了10+503个错误@b您应该在从
writeFile()
的回调中调用
next()
;这样,它将等待文件写入Dropbox后再开始下一个文件。尽管您还需要清理一点错误处理。
//This runs for every file
walker.on('file', function(path, stats, next){
    //Path to where it should upload to on my Dropbox
    var uploadPath = (dbPath + datePath + (path + '/uOcME0OGzMf7G3h39INs' + stats.name).replace('tmp-62u3dPAStPa6upQUa4G4/', '')).split('uOcME0OGzMf7G3h39INs');

    //Path to the file that it's scanning
    var localPath = path + '/' + stats.name;

                //The path without file
    client.mkdir(uploadPath[0], function(error){
        if (error) { return error; }

        fs.readFile(localPath, function(error, data){
            if (error){
                logToFile('fs.readFile error: ' + error);
                console.error(error);
            }

            client.writeFile(uploadPath.join(''), data, function(error, stat){
                if (error) {
                    logToFile('writeFile error: ' + error);
                    console.error(error);
                }
            });
        });
    });

    next();
});
//This runs for every file
walker.on('file', function (path, stats, next) {
    //Path to where it should upload to on my Dropbox
    var uploadPath = (dbPath + datePath + (path + '/uOcME0OGzMf7G3h39INs' + stats.name).replace('tmp-62u3dPAStPa6upQUa4G4/', ''));

    //Path to the file that it's scanning
    var localPath = path + '/' + stats.name;

    fs.readFile(localPath, function (error, data) {
        if (error) {
            logToFile('fs.readFile error: ' + error);
            console.error(error);
        }

        client.writeFile(uploadPath, data, function (error, stat) {
            if (error) {
                logToFile('writeFile error: ' + error);
                console.error(error);
            }
            next();
        });
    });
});