meteor-file-collection
meteor-file-collection copied to clipboard
Download fails for Android/iOS
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;
}
}
]});
@MeteorFanatic Try adding target="_self" to the element (i.e. <a href="{{link}}?download=true" target="_self"> {{shortFilename 56}} </a>
)
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