简体   繁体   中英

How to serve a pdf file from ember

I want to make a pdf document available via a link from my ember app, so I figured I would put the file in /public/assets/pdf/ and link to it as <a href='/assets/pdf/myfile.pdf'> just as I would for an image in public/assets/images . However the link isn't sending the file to the browser. I get a 200 response with a Content-Type: application/pdf header, but no file.

What's the right way to do this?

The way you described should work as there's nothing special about the way Ember handles static asset downloads. To verify, I just initialized a new project using Ember 2.3 and placed a pdf in /assets/test.pdf. I then placed the following into my application.hbs file.

<a href='/assets/test.pdf' download>Test</a>

Without the download attribute it opened as a new tab. With the download attribute the file was downloaded like normal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM