Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download fails for Android/iOS #137

Open
MeteorFanatic opened this issue Jul 26, 2016 · 2 comments
Open

Download fails for Android/iOS #137

MeteorFanatic opened this issue Jul 26, 2016 · 2 comments
Labels

Comments

@MeteorFanatic
Copy link

Hello i get this error from Iron:Router if i click on a link.

Oops, looks like there´s no route on the client or the server for url: "http://localhost:12168/gridfs/fs/md5/10721db241a9b40a8482897da1f5cb23?download=true"

helper function:
link: function() { return myFiles.baseURL + "/md5/" + this.md5; },
view:
<a href="{{link}}?download=true" > {{shortFilename 56}} </a>

collection:

myFiles = new FileCollection(
    {   resumable: true,    // Enable built-in resumable.js chunked upload support
        resumableIndexName: 'test',
        maxUploadSize:  16777216,




            http: [             // Define HTTP route
                        {
               method: 'head',
               path: '/md5/:md5',
               lookup: function (params, query) { return {md5: params.md5}; }, 
               handler: function (req, res, next) {
                  if (req.headers && req.headers.origin) {
                     res.setHeader('Access-Control-Allow-Origin', req.headers.origin );
                     res.setHeader('Access-Control-Allow-Credentials', true);
                  }
                  next();

               }
            },
                {   method: 'get',  // Enable a GET endpoint
                    path: '/md5/:md5',  // this will be at route "/gridfs/myFiles/:md5"
                    lookup: function (params, query) {  // uses express style url params
                    return { md5: params.md5 };       // a query mapping url to myFiles
                },
                                        handler: function (req, res, next) {
                                            // if (req.headers && req.headers.origin) {
                                            res.setHeader('Access-Control-Allow-Origin', '*'); // For Cordova
                                            res.setHeader('Access-Control-Allow-Credentials', true);
                                              //  }
                                        next();
                                        }
                                },
{ method: 'put',  // Enable a PUT endpoint
        path: '/md5/:md5',  // this will be at route "/gridfs/myFiles/:md5"
        lookup: function (params, query) {  // uses express style url params
          return {md5: params.md5};       // a query mapping url to myFiles
        },
        handler: function (req, res, next) {
           if (req.headers && req.headers.origin) {
             res.setHeader('Access-Control-Allow-Origin', 'req.headers.origin'); // For Cordova
             res.setHeader('Access-Control-Allow-Credentials', true);
           }
           next();
        }
      },
                                { method: 'post',  // Enable a PUT endpoint
        path: '/md5/:md5',  // this will be at route "/gridfs/myFiles/:md5"
        lookup: function (params, query) {  // uses express style url params
          return {md5: params.md5};       // a query mapping url to myFiles
        },
        handler: function (req, res, next) {
           if (req.headers && req.headers.origin) {
             res.setHeader('Access-Control-Allow-Origin', 'req.headers.origin'); // For Cordova
             res.setHeader('Access-Control-Allow-Credentials', true);
           }
           next();
        }
      },
                            { method: 'options',  // Enable an OPTIONS endpoint (for CORS)
        path: '/md5/:md5',  // this will be at route "/gridfs/myFiles/:md5"
        lookup: function (params, query) {  // uses express style url params
          return {md5: params.md5};       // a query mapping url to myFiles
        },
        handler: function (req, res, next) {  // Custom express.js handler for OPTIONS
           res.writeHead(200, {
              'Content-Type': 'text/plain',
              'Access-Control-Allow-Origin': 'req.headers.origin',  // For Cordova
              'Access-Control-Allow-Credentials': true,
              'Access-Control-Allow-Headers': 'user-agent',
              'Access-Control-Allow-Methods': 'PUT,POST, HEAD, GET' 
           });
           res.end();
           return;
        }
      }

    ]});

@hashtaggigs
Copy link

@MeteorFanatic Try adding target="_self" to the element (i.e. <a href="{{link}}?download=true" target="_self"> {{shortFilename 56}} </a>)

@vsivsi
Copy link
Owner

vsivsi commented Jul 26, 2016

Yes, @Dubbedge has the right solution. You can see this in the sample apps, for example: https://github.com/vsivsi/meteor-file-job-sample-app/blob/master/sample.html#L51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants