Meteor-files: When using Google Cloud storage, bucket.deleteFile removes all files

Created on 18 Nov 2016  路  7Comments  路  Source: veliovgroup/Meteor-Files

google cloud bucket issue

The lines from the very helpful Google Cloud getting started page:

   // Intercept file's collection remove method to remove file from Google Cloud Storage
  var _origRemove = Collections.files.remove;

  Collections.files.remove = function(search) {
    var cursor = this.collection.find(search);
    cursor.forEach(function(fileRef) {
      _.each(fileRef.versions, function(vRef) {
        var ref;
        if (vRef != null ? (ref = vRef.meta) != null ? ref.pipePath : void 0 : void 0) {
          bucket.deleteFiles(vRef.meta.pipePath, function(error) {
            bound(function() {
              if (error) {
                console.error(error);
              }
            });
          });
        }
      });
    });
    // Call the original removal method
    _origRemove.call(this, search);
  };

actually wipe out all of the my files hosted in the google cloud storage instance. This may be an more of an issue with how the demo code is interfacing with the bucket than this package, but I figured it was worth posting in case anyone else has experience this issue. Right now I am just opting to not overwrite the remote deletion method, and remove it from the local collection while allowing it to persist on Google Cloud.

For reference, here is the code that I am using which I experience this issue with:
https://github.com/radiolarian/mewsician/blob/master/both/gcloud.js#L174-L183

Thanks!

Documentation Google Cloud

Most helpful comment

I was struggled with the same problem, and found the doc here - https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/0.36.0/storage/file?method=delete
My code now is working as expected:

bucket.file(vRef.meta.pipePath).delete(function(error) {
    bound(function() {
        if (error) {
           console.error(error);
         }
    });
});

All 7 comments

Hello @jeremywrnr ,

I'm not experienced that well with gcloud, docs is provided by community. PRs is always welcome.
Guys @salmanhasni and @sethmurphy18 could you please take a look on this one? Any help is appreciated.

@jeremywrnr I have seen your code, and there i saw _console.log(fileRef)_ at https://github.com/radiolarian/mewsician/blob/master/both/gcloud.js#L178
while running the application can you please tell me how many times does your console log is emitted
and can you please share me its value, I think at some point "fileRef.versions.original.meta.pipePath" is null or empty string which wiping out all the gcloud data. please have this check and then share the console logs

if(!fileRef.versions.original.meta.pipePath)
    console.log("empty string or null");
else 
    console.log(fileRef.versions.original.meta.pipePath);

From what I can tell, unless you are passing a null reference, it shouldn't wipe everything out. I'm in agreeance with @salmanhasni on this one, you should possibly print the cursor to the console and just comment out the remove method to debug. This may be an issue with Meteor, I'm not 100% sure, I have kinda moved on to Angular now.

@jeremywrnr Any news on your end?

@salmanhasni and @sethmurphy18 - thank you guys.

Hi, sorry about the delay! Hmm it could have been that I just wasn't supplying any valid argument and then it was deleting everything... Tried running it again to grab the console.log like you mentioned, and it just prints the filename as expected: TExNYpEigy2MGMuHj-original.mp3, so I think that seems ok. Should the reference be something else?

It makes sense that I should add a check before deleting it, but just checking if the fileRef is not null before doesn't seem to stop it from wiping everything on Google Cloud, just tried again with my staging deployment. I then tried to make it very similar to how the example is, but that still wipes everything out. Here is what the vRef looks like:

vRef:  { path: 'uploads/QMPxjnru2x6CM3YRW.mp3',
           size: 13137556,
           type: 'audio/mp3',
           extension: 'mp3',
           meta: { pipePath: 'rJZ3wEDBd5ACx7Cuk-original.mp3' }
       }

Thank you for the help!

I was struggled with the same problem, and found the doc here - https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/0.36.0/storage/file?method=delete
My code now is working as expected:

bucket.file(vRef.meta.pipePath).delete(function(error) {
    bound(function() {
        if (error) {
           console.error(error);
         }
    });
});

Thanks @logvik! Just updated my code with this, looks like that fixes things for me 馃憤

Was this page helpful?
0 / 5 - 0 ratings