Sense/Net download text file - sensenet

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.

Related

How to accept a pdf file from server in ember

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();

using content-length when downloading a file using WCF Rest?

We are developing an application for Web. Inside that application, to download a file, I have created a WCF Rest service that will download the files based on this link Download using WCF Rest. The purpose is to check for user authentication before downloading. I used streaming concept to download the file. It is now that I have found out few things
When the user downloads the file, he is not able to determine what are the file size and the time remaining. I analyzed and found out that the reason is because, it’s using the “Transfer Encoding: chunked” in the header so that the file will be downloaded in chunks. One of the advantages is that the memory consumption is less in the server even when there are many users downloading a file. So I thought of adding “Content-Length” header, but I found out that you can use only either one of the headers not both. So I was thinking how Hotmail and Gmail were downloading attachments. From my investigation, I found out that Hotmail uses chunking header whereas Gmail uses Content-length header. Also in the case of Gmail, it is also checking if the session is active or not then downloads the file accordingly. I want to achieve the following
a) Like Gmail, I want to check if the session is active or not and then downloads the files accordingly. What will be the method for me to implement it?
b) When downloading the file, I want to use Content-Length header instead of Chunked header. Also the memory consumption should be less. Can we achieve it in WCF Rest? If so how?
c) Is it possible for me to add a header in WCF that will display the file size in the browser Downloads window?
d) When downloading an inline images from WCF, I found out that the image after loading is not cached in local machine. I was thinking that once an image is shown in an HTML page, it will get automatically cached and the next time user visits the page, the image will load from cache instead from server. I want to cache the inline images to cache, what is the option that I can use for it? Are there any headers that I need to specify when downloading an inline image from server?
e) When I download a zip file using WCF in IPhone Chrome browser, it’s not downloading at all. But the same link works in Android Chrome browser. What could be the problem? Am I missing header in WCF?
Are there any methods that will achieve the above?
Regards,
Jollyguy

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.

Download dynamic generated pdf from dynamic url which is being viewed in webbrowser control in adobe viewer in vb.net

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")

Error 404 for file download without browser redirection?

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();
}