question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fix code in Google Cloud Storage Integration Wiki Page

See original GitHub issue

I have copied the example code you have in the Google Cloud Storage Integration Wiki page, and it worked flawlessly when uploading single image. However, I had problems when using it with files with subversions (such as when generating thumbnails with the example in the Image Processing page) - specifically it was uploading the original file twice.

I think the issues lies in here:

onAfterUpload: function(fileRef) {
    // In the onAfterUpload callback, we will move the file to Google Cloud Storage
    var self = this;
    _.each(fileRef.versions, function(vRef, version){
      // We use Random.id() instead of real file's _id
      // to secure files from reverse engineering
      // As after viewing this code it will be easy
      // to get access to unlisted and protected files
      var filePath = "files/" + (Random.id()) + "-" + version + "." + fileRef.extension;
      // Here we set the neccesary options to upload the file, for more options, see
      // https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.36.0/storage/bucket?method=upload
      var options = {
        destination: filePath,
        resumable: true
      };

      bucket.upload(fileRef.path, options, function(error, file){
...

it’s using _.each to go through each version of the file, but when specifying the source file to upload it uses ‘fileRef.path’ which is the same for each version. To upload the correct file, it should be using vRef.path, which is the specific path for that version.

This is further confirmed by looking at the object structure of the fileRef object passed to the function:

{ size: 829970,                                         
  type: 'image/png',                                    
  name: 'Picture1.png',                                 
  meta: {},                                             
  ext: 'png',                                           
  extension: 'png',                                     
  extensionWithDot: '.png',                             
  mime: 'image/png',                                    
  'mime-type': 'image/png',                             
  _id: 'vu6rreiCgvBChc5Gp',                             
  userId: 'f4v3Bo4qTsdYbwFAR',                          
  path: 'C:/Test\\vu6rreiCgvBChc5Gp.png',               
  versions:                                             
   { original:                                          
      { path: 'C:/Test\\vu6rreiCgvBChc5Gp.png',         
        size: 829970,                                   
        type: 'image/png',                              
        extension: 'png' },                             
     thumbnail:                                         
      { path: 'C:/Test/thumbnail-vu6rreiCgvBChc5Gp.png',
        size: 18945,                                    
        type: 'image/png',                              
        extension: 'png',                               
        meta: [Object] } },                             
...

Does this make sense? It started working correctly for me after I made this fix, I think this is the expected behaviour. Happy to make a PR to the docs if you give me the green light.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

0reactions
dr-dimitrucommented, Jun 29, 2019

Fixed by #699, Feel free to reopen it in case if the issue is still persists on your end.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cloud Storage Errors and Error Handling - App Engine
An unauthorized request was received by Google Cloud Storage. This error can occur if an authorized app is using an access token that...
Read more >
CDN Hosting at Google Cloud Storage - GitHub
Google Cloud storage does not compress on the fly but should decompress on the fly for old browsers that can't accept decompressed files....
Read more >
Cloud Storage for Firebase - Google
Cloud Storage for Firebase is built for app developers who need to store and serve user-generated content, such as photos or videos.
Read more >
Wiki - GitLab Docs
Create or edit wiki pages locally. Wikis are based on Git repositories, so you can clone them locally and edit them like you...
Read more >
Google Drive - Wikipedia
Google Drive is a file storage and synchronization service developed by Google. Launched on April 24, 2012, Google Drive allows users to store...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found