Fix code in Google Cloud Storage Integration Wiki Page
See original GitHub issueI 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:
- Created 6 years ago
- Comments:6 (5 by maintainers)

Top Related StackOverflow Question
https://github.com/VeliovGroup/Meteor-Files/pull/698
Fixed by #699, Feel free to reopen it in case if the issue is still persists on your end.