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();
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.
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.
I am using PhantomJS 1.9.7 to scrape a web page. I need to send the returned page content to S3. I am currently using the filesystem module included with PhantomJS to save to the local file system and using a php script to scan the directory and ship the files off to S3. I would like to completely bypass the local filesystem and send the files directly from PhantomJS to S3. I could not find a direct way to do this within PhantomJS.
I toyed with the idea of using the child_process module and pass in the content as an argument, like so:
var execFile = require("child_process").execFile;
var page = require('webpage').create();
var content = page.content;
execFile('php', '[path/to/script.php, content]', null, function(err,stdout,stdin){
console.log("execFileSTDOUT:", JSON.stringify(stdout));
console.log("execFileSTDERR:", JSON.stringify(stderr));
});
which would call a php script directly to accomplish the upload. This will require using an additional process to call a CLI command. I am not comfortable with having another asynchronous process running. What I am looking for is a way to send the content directly to S3 from the PhantomJS script similar to what the filesystem module does with the local filesystem.
Any ideas as to how to accomplish this would be appreciated. Thanks!
You could just create and open another page and point it to your S3 service. Amazon S3 has a REST API and a SOAP API and REST seems easier.
For SOAP you will have to manually build the request. The only problem might be the wrong content-type. Though it looks as if it was implemented, but I cannot find a reference in the documentation.
You could also create a form in the page context and send the file that way.
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")
on a website I display links to PDF files.
When the first time call for a file arrives, the request gets redirected to a php-script that generates and returns the file. Additionally, it saves the file to the linked location so next time it will be directly availibe. I send the pdf mime type to make the browser open a download dialog instead of redirecting.
Due to reasony beyond my control, one out of 20 files cannot be generated.
How to respond?
Error 404 or 500 would direct the browser to an error page, while sending a mime-type would let the user download an empty / defect pdf file. Is there an established best practise? How to let the user know that a file link is broken, yet keep him on the site without redirect?
I had the same problem and solved it as follows:
If you have link to file, for example:
<a download href="/files/document.pdf">Click to download</a>
And if you don't want the browser redirect to blank/error page if the file doesn't exist, just reply with 204 without any content.
Nothing will happen, the user will stay where he is without redirection.
In php it would look something like this:
if (!readfile("/files/document.pdf") {
http_response_code(204);
die();
}