So my question is should the content type be set before uploading? And also, we get only a link from the backend team, a url that gives the file path, that we open in new tab using:window. Kailas I don't understand what you're trying to do..
These headers have no effect on a file upload, you need to have the code behind the url set the headers every time it is downloaded by the client. ColinM Thanks buddy, you said it right, the issue when we debugged was the mime type was set while uploading the files. This should be done by the back-end team. I tried to get codes on how to add headers in java script but was not successful. Thanks, as I got the real idea cleared from you Show 5 more comments.
It uses the custom filename specified on the view side. Christophe Roussy Christophe Roussy Akshay Akshay 2, 3 3 gold badges 32 32 silver badges 70 70 bronze badges. If you have control over the server code you should use 'attachement' as this will allow to use the same filename generation code. If you have no control over the server this is a good solution.
This is a brilliant solution to the problem however, as always, IE is holding us back from using it: caniuse. Important to note that this does not work across domains e. If downloading from one domain, the download attribute will not work if content is stored on a different domain.
CORS may allow that content to pass through haven't tested. Yes figured! Show 1 more comment. This is for ASP. FilePath, FileMode. Open, FileAccess. Leon van Wyk Leon van Wyk 8 8 silver badges 7 7 bronze badges. Oops, there were typing errors in my previous post.
Andrew Barber 38k 20 20 gold badges 91 91 silver badges bronze badges. What previous post? If you have Apache add this to the. Alexander Alexander 43 1 1 silver badge 4 4 bronze badges. Kindly suggest me. I want to update Chrome. For Mac OS X Learn how to update. Set Google Chrome as my default browser. Help make Google Chrome better by automatically sending usage statistics and crash reports to Google. Learn more. Gmail Search Google Pay. Translate Translator. Explore Google tools.
Safety by design Take control of your online safety Chrome works hard to protect your data and privacy online. Explore safety. Helpful features built-in Fast, easy-to-use tools for browsing From password check, dark mode, and the Google address bar, Chrome helps you get things done and stay safe online. Setting the content type should do it.
Which browser is it? Which browser? Octet-stream should be the right answer, but older versions of IE used to try and "sniff" the content type regardless of what the web server was telling it — Paolo.
Content-Disposition attachment will do it. Add a comment. Active Oldest Votes. Therefore, your method should be written as follows this won't compile as it is a mere representation : response. Improve this answer. Vineet Reynolds Vineet Reynolds ChristopheRoussy, yes no one claimed as such.
Stop spamming all the answers here. I want to inform other SO users about it being a hack and how it works as this is not mentioned anywhere, here is an explanation on SO: stackoverflow. Vladimir Dyuzhev Vladimir Dyuzhev I would guess it is "you're doing everything correctly" that burned you. The accepted answer makes it clear what was incorrect. This markup is easier to understand and is supported by all modern browsers, but may not be supported by all content management systems.
If for whatever reason, you cannot add the download attribute in the case that you cannot directly edit the HTML of your web page , you can optionally compress the file using zip, and instruct the user to download the zip file.
You can alternatively explain to the user that they should right click on the link and select download. If you have no other alternatives to force the file to download, you can host it on a file hosting service such as Google Docs.
The most common file types that are affected by this behavior are PDF files and images.
0コメント