Meteor-files: There is no route for the path

Created on 1 Jun 2017  ·  18Comments  ·  Source: veliovgroup/Meteor-Files

HI everybody,

Thanks for this awesome package,

i setup the package to work with S3 upload, everything seems to work fine...
my problem is to display the images on the client,
i have a helper who bring me the url with the .link() function.
but when i try to access http://localhost:3000/cdn/storage/2uvdTA7XXnNNtizss.png
i've got an error from flow router :
kadira_flow-router.js?hash=4ca3941…:519 There is no route for the path: /cdn/storage/2uvdTA7XXnNNtizss.png

how can i setup flow router to drive the request correctly ? what i'am doing wrong ?
i presume the magic is located under the interceptDownload function ?

Thanks for your help.

Best regards,
Léo

question

Most helpful comment

yes, i did !!!! and it woks right now...
I'm sorry for all of this...and thank you so much for your time...i only install package with meteor add...and didn't check the version...

i run
meteor update ostrio:file
(it update to 1.7.)

then i had to install fs extra :
meteor npm install fs.extra --save
and file type,
meteor npm install file-type --save

because i had this error :
Error: Can't find npm module 'file-type'. Did you forget to call 'Npm.depends' in package.js within the 'ostrio_files' package?
same for fs extra.

but now, everything is working...thank you so much !!!!!!!

All 18 comments

Hello @lleoooell ,

Could you please post your .meteor/packages file?
My quick guess is kadira:flow-router placed above ostrio:files, if I'm right - that means flow-router intercepts requests and not passing it no next listener. To solve this, simply place ostrio:files above kadira:flow-router in .meteor/packages file

Hi @dr-dimitru
Thanks for your quick answer !
Your guess was right, but it solved 50% of the problem, with ostrio:files above kadira:flow-router, there is no more error message of 'no route for path' in the client console...but still a 404 page not found...

(this fix on the packages file make me thinking about how my deployment with mup - i'm new with this tool - will be done, if i change my packages lines order on my local laptop, will this change be reflected on my server or a new package file will be created ? - maybe this is a noob question because mup only copy paste my local package file to my remote instance ? sorry for this...)

thanks a lot,

capture d ecran 2017-06-01 a 22 10 06
capture d ecran 2017-06-01 a 22 09 44

  1. Does this works locally?
  2. Enable debug mode with {debug: true} passed into FilesCollection constructor - so we will see if request reaches FilesCollection, and where it stuck. Post here both Client and Server logs
  1. yes, It works locally, after i remove onAfterUpload() and interceptDownload() functions in my files.js.
    url generated by .link() is :
    http://localhost:3000/cdn/storage/Images/zhSqdv9QjowCfDLey/original/zhSqdv9QjowCfDLey.png
    (with S3 setup was : http://localhost:3000/cdn/storage/2uvdTA7XXnNNtizss.png)
    capture d ecran 2017-06-01 a 22 33 14
    (only the first object is find because the previous one was uploaded with my S3 setup)
    2 See here server logs :
    capture d ecran 2017-06-01 a 22 34 52

my guess is that i really have a problem with my intercept function...

  1. How do you generate a link? With FileCursor#link() method or {{fuleURL fileObj}} helper?
  2. My guess something wrong in onAfterUpload() as link generated out of the record in MongoDB, and your screenshot (with requested URL) indicates what something is missing

when i upload a picture with my S3 setup i presume everything is ok for the upload part :
capture d ecran 2017-06-01 a 22 42 38
but as soon as i try to display it :
capture d ecran 2017-06-01 a 22 44 31

and here is the function, basically the one pasted from the example :

 interceptDownload(http, fileRef, version) {
      let path;

      if (fileRef && fileRef.versions && fileRef.versions[version] && fileRef.versions[version].meta && fileRef.versions[version].meta.pipePath) {
        path = fileRef.versions[version].meta.pipePath;
      }

      if (path) {
        // If file is successfully moved to AWS:S3
        // We will pipe request to AWS:S3
        // So, original link will stay always secure

        // To force ?play and ?download parameters
        // and to keep original file name, content-type,
        // content-disposition, chunked "streaming" and cache-control
        // we're using low-level .serve() method
        const opts = {
          Bucket: s3Conf.bucket,
          Key: path
        };

        if (http.request.headers.range) {
          const vRef  = fileRef.versions[version];
          let range   = _.clone(http.request.headers.range);
          const array = range.split(/bytes=([0-9]*)-([0-9]*)/);
          const start = parseInt(array[1]);
          let end     = parseInt(array[2]);
          if (isNaN(end)) {
            // Request data from AWS:S3 by small chunks
            end       = (start + this.chunkSize) - 1;
            if (end >= vRef.size) {
              end     = vRef.size - 1;
            }
          }
          opts.Range   = `bytes=${start}-${end}`;
          http.request.headers.range = `bytes=${start}-${end}`;
        }

        const fileColl = this;
        s3.getObject(opts, function (error) {
          if (error) {
            console.error(error);
            if (!http.response.finished) {
              http.response.end();
            }
          } else {
            if (http.request.headers.range && this.httpResponse.headers['content-range']) {
              // Set proper range header in according to what is returned from AWS:S3
              http.request.headers.range = this.httpResponse.headers['content-range'].split('/')[0].replace('bytes ', 'bytes=');
            }

            const dataStream = new stream.PassThrough();
            fileColl.serve(http, fileRef, fileRef.versions[version], version, dataStream);
            dataStream.end(this.data.Body);
          }
        });

        return true;
      }
      // While file is not yet uploaded to AWS:S3
      // It will be served file from FS
      return false;
    }

Could you add console.log(fileColl) after it's defined and before .serve to check what is there?

I'm generating a link like that :

_in my template html :

<img class="pulseImg" src="{{getImageById imgId}}">

getImageById is a global client helper :

Template.registerHelper('getImageById', function(id) {
    var test = Images.findOne({"_id" : id});
    console.log(test.link());
    return test.link();

});

here is my console log fileCol

capture d ecran 2017-06-01 a 22 55 52

Could you check what is inside test ? console.log(test)

according to your log fileCol is exists and has right value.
What FilesCollection version you're on? May be it's too old to have .serve?

test looks like this :
capture d ecran 2017-06-01 a 22 59 07

ostrio file version is :
ostrio:[email protected]

(many thanks for your help)

Yes ostrio:[email protected] is too old to have .serve, and may have other bugs.
Could you update?

Funny thing today ostrio:[email protected] is exactly an year old

yes, i did !!!! and it woks right now...
I'm sorry for all of this...and thank you so much for your time...i only install package with meteor add...and didn't check the version...

i run
meteor update ostrio:file
(it update to 1.7.)

then i had to install fs extra :
meteor npm install fs.extra --save
and file type,
meteor npm install file-type --save

because i had this error :
Error: Can't find npm module 'file-type'. Did you forget to call 'Npm.depends' in package.js within the 'ostrio_files' package?
same for fs extra.

but now, everything is working...thank you so much !!!!!!!

but now, everything is working...thank you so much !!!!!!!

Great! 👍

then i had to install fs extra :
and file type,

Yes, latest release have annoying issue with NPM dependencies, stay tuned for updates at #420

I'm sorry for all of this...and thank you so much for your time...i only install package with meteor add...and didn't check the version...

No worries, I'm glad to help. Check out our other meteor packages.

Please, support this project by:

done ^^

@fmorgens If you've solved your issue — feel free to share a solution

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tuarrep picture tuarrep  ·  4Comments

JanSchuermannPH picture JanSchuermannPH  ·  3Comments

rlhk picture rlhk  ·  4Comments

sylido picture sylido  ·  3Comments

dr-dimitru picture dr-dimitru  ·  3Comments