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.
Related
When I try to download the text file in sensenet, the text file will open in browser but not downloaded, could you give some suggestions about how to set to download text file directly?
It's handled by the browser. If it can open a certain file type, then it will show it instead of downloading.
On server side you can force to download file types on your website if your http handler use disposition when set response stream:
response.AppendHeader("Content-Disposition", "attachment");
With sensenet you have to write your own http handler or modify ProcessRequest of SenseNetStaticFileHandler.cs.
MSDN is not too helpful on this topic, but you can find some information on this here.
On client side there is another solution, if you can change the html code of the link. With html5 <a> tag has got a download attribute that forces the linked file to download instead of navigate the browser to it. It works if the browser supports it. See HTML download Attribute.
Consider the below URL:
http://localhost:4200/abc/secured/rest/name/166
This URL returns a PDF file from the server. Code is done to successfully trigger the service URL and get the response code as 200.
What code should be written in ember to capture the PDF file and prompt a save as window to the User for saving the PDF file in local machine.
You can try ember-pdfjs,
https://github.com/mysterlune/ember-pdfjs
And provide the URL as the src for the pdf-document which can be used to render the pdf inside a template.
In the same page you can provide a link like below which provide an download attribute (HTML5 attribute, not support by ledgacy browser)
Download Your File
Code above will let the browser download the file instead of open it for viewing.
execute this code in button click action handler.
let link = document.createElement('a');
link.href = 'http://localhost:4200/abc/secured/rest/name/166';
link.target = '_blank';
link.click();
Is there a way to supply Google Docs Viewer with a source from a proxy download? Such as from https://www.url.com/download.php?file=fdg46fgd (random download code).
The download script headers look like this:
header("Content-Type: " . $mime);
header("Content-Disposition: attachment; filename=\"$name\"");
header("Content-Length: " . $size);
header("Cache-Control: private");
It prints the contents after the headers are established. This works fine when you enter the link into the browser and works as expected. I have also tried using inline instead of attachment but the Google Doc Viewer always displays "No Preview Available". The document viewer code looks like this:
<iframe src="https://docs.google.com/gview?url=https://www.url.com/download.php?file=fdg46fgd&embedded=true" style="width:800px; height:700px;" frameborder="0"></iframe>
I have tried using different documents such as pdfs, docx, etc.
If I use a direct link it will display properly, but not when using the download script. I have seen people using a download script based URL before and it seemed to work for them. Does this not work with Google Doc Viewer anymore? Any suggestions? Any help appreciated, thanks!
Because the process in your download URL have validation (ex: check login, limit user, ...).
Remove this validation code, Google Doc Viewer can be open file you want.
I am developing a windows application in vb.net in which i have a url which first ask me to login on the website and then display a view pdf link. As i make it click it again redirect to another page where instead of asking for download pdf it opens it in my web browser control. Now i want to save that opened pdf on my specified path. I have googled a lot but didn't find any solution for the same. I even found some related posts but none of them have my answer. Here my pdf url doesnt contains any file name like '.pdf'. Url contains some token values. To open this url it requires login on the website. I am trying to download pdf file for many days. Please help me.
you have to push your file using http headers
Unique HTTP Headers Returned
because these headers are the only thing controlling how your browser handles the file.
Save As Mode (askapache_pdf=s)
Content-Disposition: attachment
Content-Type: application/pdf
for more info goto http://www.askapache.com/htaccess/pdf-cookies-headers-rewrites.html#Unique_HTTP_Headers_Returned
This does not have anything to do with server side scripting language its same that you have to add a response in your header of http request. But anyway in ASP you should try something like below
Response.AddHeader("content-disposition", "attachment;filename=somefile.ext")
using ASP.NET MVC 2.0
I am making an amazon S3 downloader.
In download method I prepare a url something like http://s3.amazon.com/mysite.com/image.gif?awsKey=abcde
I redirect the user to that url (which opens that image.gif in the browser)
I see the image opened in the browser , but not as SAVE AS window to save at a location.
I have heard that I can add HEADERS in Response which can force SAVE AS dialog to save the file.
Any idea how those headers re added?
That would be the Content-Disposition header set to "attachment". However, the webservers serving s3.amazon.com would have to set this header, and changing that is outside of your control.