vsivsi / meteor-file-collection

Extends Meteor Collections to handle file data using MongoDB gridFS.
http://atmospherejs.com/vsivsi/file-collection
Other
159 stars 37 forks source link

Downloading a file restoring original name #39

Closed dpatte closed 9 years ago

dpatte commented 9 years ago

What would the html link look like, or process be, to download a file from a file collection, restoring its original name?

I have tried a href="{{path}}" download="{{filename}}" {{filename}} /a but it is named according to its fileid, not its filename.

vsivsi commented 9 years ago

Hi, thanks for your question.

If the filename you would like to use is the same as the filename stored for the file in the collection, then you shouldn't need to specify the filename at all in the HTML, as that is the default case. This is documented in the "HTTP request behaviors" section of the README.

So, your HTML should look like:

<a href="{{path}}?download=true"> ... </a>

Note that the "download" part is actually an URL query, not a separate attrib on the anchor tag as you show in the OP. It all goes in the href attrib. If you want to change the filename from what is stored for the file (or if there is no filename in the collection):

<a href="{{path}}?download=true&filename={{filename}}"> ... </a>

Hope this helps.

vsivsi commented 9 years ago

If you look here in the sample app, you can see how it works there:

https://github.com/vsivsi/meteor-file-sample-app/blob/master/sample.html#L42

dpatte commented 9 years ago

Thanks you. Works great. Your quick response is appreciated. Very useful package!

vsivsi commented 9 years ago

Great, happy to help.