You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Access Denied: when the user don't have permissions.
Incorrect client options: when the bucket doesn't exist, or region is not support.
But it is never returns an error.
This is how it is implemented:
import{FilesCollection}from'meteor/ostrio:files';import{Meteor}from'meteor/meteor';import{Random}from'meteor/random';import_from'lodash';importknoxfrom'knox';importRequestfrom'request';exportconstMAX_ALLOWED_SIZE_MB=2;exportconstMAX_ALLOWED_SIZE_KB=MAX_ALLOWED_SIZE_MB*1024;exportconstMAX_ALLOWED_SIZE_B=MAX_ALLOWED_SIZE_KB*1024;exportconstALLOWED_FILE_TYPES=['png','jpg','jpeg'];exportconstALLOWED_FILE_TYPES_REGEXP=newRegExp(ALLOWED_FILE_TYPES.join('|'),'i');// Declaring variables outside the isServerletbound;letclient;letcfdomain;if(Meteor.isServer){// Fix CloudFront certificate issue Read:// https://github.com/chilts/awssum/issues/164process.env.NODE_TLS_REJECT_UNAUTHORIZED=0;bound=Meteor.bindEnvironment(function(callback){returncallback();});// Setup CloudFront domain and S3 client configconstconfig=Meteor.settings.amazonAWSS3.productImages;cfdomain=config.cfdomain;client=knox.createClient({key: config.client.key,secret: config.client.secret,bucket: config.client.bucket,region: config.client.region});}constProductImages=newFilesCollection({debug: false,throttle: false,storagePath: 'assets/app/uploads/productImages',collectionName: 'productImages',allowClientCode: false,// Disallow remove files from ClientonBeforeUpload(file){if(file.size>MAX_ALLOWED_SIZE_B){return'exceed-max-allowed-size';}if(!ALLOWED_FILE_TYPES_REGEXP.test(file.extension)){return'invalid-file-type';}returntrue;},onAfterUpload: function(fileRef){// In onAfterUpload callback we will move file to AWS:S3constself=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 filesconstfilePath="product_images/originals/"+(Random.id())+"-"+version+"."+fileRef.extension;client.putFile(vRef.path,filePath,function(error,res){console.log(error);// Error is always nullbound(function(){letupd;if(error){console.error(error);}else{upd={$set: {}};upd['$set']["versions."+version+".meta.pipeFrom"]=cfdomain+'/'+filePath;upd['$set']["versions."+version+".meta.pipePath"]=filePath;self.collection.update({_id: fileRef._id},upd,function(error){if(error){console.error(error);}else{// Unlink original files from FS after successful upload to AWS:S3self.unlink(self.collection.findOne(fileRef._id),version);res.resume();// Recommended in Knox docs.}});}});});});},}
The text was updated successfully, but these errors were encountered:
I'have being testing Knox for errors such as:
But it is never returns an error.
This is how it is implemented:
The text was updated successfully, but these errors were encountered: