Google Cloud Storage - upload error: rename operation gcs-resumable-upload.json not allowed

I'm just trying to follow this tutorial on how to upload files to gcs using Node and Express. But the following error causes my application to crash. As a rule, I can upload one file without problems in the first run. But I will get this error after running multiple requests even in another file. When I try to upload, say, 5 files at a time, this error causes my application to crash even on the first run. I see that the process is trying to rename the file in the .config folder. Is this normal behavior? If so, is there a job?

Window: v10.0.10586 Node: v4.3.1 Express: v4.13.1

Error: EPERM: operation not permitted, rename 'C:\Users\James Wang.config\configstore\gcs-resumable-upload.json.2873606827' -> 'C:\Users\James Wang.config\configstore\gcs-resumable-upload.json' at Error (native) at Object.fs.renameSync (fs.js:681:18) at Function.writeFileSync as sync at Object.create.all.set (C:\Users\James Wang\gi-cms-backend\node_modules\configstore\index.js:62:21) at Object.Configstore.set (C:\Users\James Wang\gi-cms-backend\node_modules\configstore\index.js:93:11) at Upload.set (C:\Users\James Wang\gi-cms-backend\node_modules\gcs-resumable-upload\index.js:264:20) at C:\Users\James Wang\gi-cms-backend\node_modules\gcs-resumable-upload\index.js:60:14 at C:\Users\James Wang\gi-cms-backend\node_modules\gcs-resumable-upload\index.js:103:5 at Request._callback (C:\Users\James Wang\gi-cms-backend\node_modules\gcs-resumable-upload\index.js:230:7) at Request.self.callback (C:\Users\James Wang\gi-cms-backend\node_modules\request\request.js:199:22) at emitTwo (events.js:87:13) at Request.emit (events.js:172:7) at Request. (C:\Users\James Wang\gi-cms-backend\node_modules\request\request.js:1036:10) at emitOne (events.js:82:20) at Request.emit (events.js:169:7) at IncomingMessage. (C:\Users\James Wang\gi-cms-backend\node_modules\request\request.js:963:12) [nodemon] app crashed - waiting for file changes before starting...

UPDATE: {: false}, @stephenplusplus , "EPERM: ". {[ERROR: ETIMEDOUT]: "ETIMEDOUT", connection: false} 1,5 . .

, ~ 2,5 . 3 , ~ 1.5mb.

" ", , , , resumable = false?

express multer node.

, :

  // Express middleware that will handle an array of files. req.files is an array of files received from 
// filemulter.fields([{field: name, maxCount}]) function. This function should handle 
// the upload process of files asychronously
function sendFilesToGCS(req, res, next) {
    if(!req.files) { return next(); }

    function stream(file, key, folder) {
        var gcsName = Date.now() + file.originalname;
        var gcsFile = bucket.file(gcsName);
        var writeStream = gcsFile.createWriteStream({ resumable: false });
        console.log(key);
        console.log('Start uploading: ' + file.originalname);

        writeStream.on('error', function(err) {
            console.log(err);
            res.status(501).send(err);
        });
        writeStream.on('finish', function() {
            folder.incrementFinishCounter();
            req.files[key][0].cloudStorageObject = gcsName;
            req.files[key][0].cloudStoragePublicUrl = getPublicUrl(gcsName);
            console.log('Finish Uploading: ' + req.files[key][0].cloudStoragePublicUrl);
            folder.beginUploadNext();
        });
        writeStream.end(file.buffer);
    };

    var Folder = function(files) {
        var self = this;
        self.files = files;
        self.reqFilesKeys = Object.keys(files); // reqFilesKeys is an array of keys parsed from req.files
        self.nextInQuene = 0; // Keep track of the next file to be uploaded, must be less than reqFilesKeys.length
        self.finishCounter = 0; // Keep track of how many files have been uploaded, must be less than reqFilesKeys.length

        console.log(this.reqFilesKeys.length + ' files to upload');
    };

    // This function is used to initiate the upload process. 
    // It also called in the on-finish listener of a file write-stream,
    // which will start uploading the next file in quene
    Folder.prototype.beginUploadNext = function() {
        // If there still file left to upload,
        if(this.finishCounter < this.reqFilesKeys.length) {
            // and if there still file left in quene
            if(this.nextInQuene < this.reqFilesKeys.length) {
                // upload the file
                var fileToUpload = this.files[this.reqFilesKeys[this.nextInQuene]][0];
                stream(fileToUpload, this.reqFilesKeys[this.nextInQuene], this);
                // Increment the nextInQuene counter, and get the next one ready
                this.nextInQuene++;             
            }
        } else {
            console.log('Finish all upload!!!!!!!!!!!!!!!!!!!!!!');
            next();
        }
    };

    Folder.prototype.incrementFinishCounter = function() {
        this.finishCounter++;
        console.log('Finished' + this.finishCounter + ' files');
    };

    var folder = new Folder(req.files);

    // Begin upload with 3 streams
    /*for(var i=0; i<3; i++) {
        folder.beginUploadNext();
    }*/

    //Upload file one by one
    folder.beginUploadNext();
}
+1
1

bower. : bower cache clean --allow-root

, .

0

Source: https://habr.com/ru/post/1650933/


All Articles