Display csv inside firefox browser - firefox

I need to open a csv file within firefox. By default, it asks me to choose a download location or to open it with an external program. However, regarding the context, I have to display it straight away inside the browser as plain text, without passing by the popup screen which asks me what to do with the file.
I tried to tweak the Firefox "mimetype.rdf" in order to force the content type "text/csv" to be opened in browser. However, I don't find much information about this file, so I was more or less guessing... This is what I came out with:
<RDF:Description RDF:about="urn:mimetype:text/csv"
NC:value="text/csv"
NC:editable="false"
NC:description="CSV page"
NC:fileExtensions="csv">
<NC:handlerProp RDF:resource="urn:mimetype:handler:text/plain"/>
</RDF:Description>
My idea was to force firefox to treat text/csv as text/plain. This code does not work. But anyway, I managed to force content type using "Mason" firefox extension. However, when the browser sees it as a text/plain, it propose me to open it with notepad or download, does not help me much.
I tried other content types, the text/html, text/xml, it always asks me to choose an external application or download.
I tried to use several extensions, "openInBrowser" and "ViewAsText" make me able to do what I want, but I have to explicitely go in a menu and click the "view as text in the browser", no possibility to set a behavior for the content type "text/csv".
How can I explain that I want all the "text/csv" to be opened inside firefox by default?
Any idea?
Thanks

You could have an upload field where the CSV file gets uploaded to the server. Using server-side code (ASPX for example) you could upload the file, then read the contents of the CSV file and display the results using a Response.Write to the browser.

Related

Load PDF file in codeigniter

I want to load a pdf file located in upload/grilles/ where upload is located in the root.
My code:
<?php echo $nomFichier; ?>
When I click in the link, codeigniter doesn't want to display the document unlike in a site without framework that display.
Why?
Thanks !
This is not a codeigniter problem, but a browser (Firefox) issue.
I'd recommend the PDF.JS library, which is a general-purpose, web standards-based platform for parsing and rendering PDFs.
note: your above example behave (checked on localhost ) in other browsers than FireFox as follows:
Chrome Version 34.0.1847.137: shows pdf in new window right away
IE 11: asks for permission to show the pdf, if granted shows pdf in new window right away
Safari (for windows) 5.1.7.: shows pdf in new window right away
Opera 12.11: shows pdf in new window right away
So....
It's just my URL.
The file name contains a space, but I injected the name in the url which gave:
localhost/xxxx/yyy/file%20test.pdf
but the url's file is:
localhost/xxxx/yyy/file_test.pdf
Sorry for the inconvenience

How to download pdf file in ruby without .pdf in the link

I need to download a pdf from a website which does not provide a link ending with (.pdf) using ruby. Manually, when i click on the link to download the pdf, it takes me to a new page and the dialog box to save/open the file appears after some time.
Please help me in downloading the file.
The link
You an do this
require 'open-uri'
File.open('my_file_name.pdf', "wb") do |file|
file.write open('http://someurl.com/2013-1-2/somefile/download').read
end
I have been doing this for my projects and it works.
If you just need a simple ruby script to do it, I'd just run wget. Like this exec 'wget "http://path.to.the.file/and/some/params"'
At that point though, you might as well run wget.
The other way, is to just run a get on the page that you know the pdf is at
source = Net::HTTP.get("http://the.website.com", "/and/some/params")
There are a number of other http clients that you could use, but as long as you make a get request to the endpoint that the pdf is at, it should give you the raw data. Then you can just rename the file, and you'll have the pdf
In your case, I ran the following commands to get the pdf
wget http://www.lawcommission.gov.np/en/documents/prevailing-laws/constitution/func-download/129/chk,d8c4644b0f086a04d8d363cb86fb1647/no_html,1/
mv index.html thefile.pdf
Then open the pdf. Note that these are linux commands. If you want to get the file with a ruby script, you could use something like what I previously mentioned.
Update:
There is an added complication that was not initially stated, which is that the url to the pdf changes every time there is an update to the pdf. In order to make this work, you probably want to do something involving web scraping. I suggest nokogiri. This way you can look at the page where the download is and then perform a get request on the desired URL. Furthermore, the server that hosts the pdf is misconfigured, and breaks chrome within a few seconds of opening the page.
How to solve this problem: I went to the site, and refreshed it. Then broke the connection to the server (press the X where there would otherwise be a refresh button). Then right click next to the download link, and select inspect element. Then browse the dom to find something that is definitively identifying (like an id). Thankfully, I found something <strong id="telecharger"> Download</strong>. This means that you can use something like page.css('strong#telecharger')[0].parent['href'] This should give you a URL. Then you can perform a get request as described above. I don't have time to make the script for you (too much work to do), but this should be enough to solve the problem.

File Upload - Customise Browse window

I've got a bit tricky problem... I've got this file upload control which is only used for uploading profile images. When it is clicked it opens a Windows explorer Browse window. I would like this window to have the filter preselected on image files (.jpg, .png, etc.) and mine only has "All Files". This is what I'm talkin about:
I would also like to set a default location for the folder. Is there any way to set this Browse window?
You could achieve that if your browser supports HTML5 by adding the accept tag to your file input:
<input type="file" name="file" accept="image/jpg, image/gif" />
If your browser doesn't support HTML5 you are pretty much busted. Prefiltering file input dialogs in legacy browsers to a certain file type simply is not supported. You will have to use Flash or some equivalent client side scripting technology. You might take a look at some file upload controls such as Plupload, BlueImp and Uploadify which are abstracting much of this hassle for you.

Turn off built-in rss reader in Firefox 13

A couple of years ago, I designed a bunch of automatic tests for a webapplication using Molybdenum. Some of these checked the data showed in a rss feed through an xml parser. The test required the browser to show the rss as a simple xml file.
At that time I managed to turn off firefox built-in rss reader changing a parameter in the feedconverter.js file. With the major updates in Firefox (4.0 to now) this file is missing and the developers seems to have left no room for this kind of trick.
Do you know a native way to turn off the built-in rss reader?
P.S. = Solutions using the view-source: URL suffix does not work in this case, because the open command answers Failure: Access to restricted URI denied
Things that don't work:
setting "Web feed" content handler to "Preview in Firefox" (shows formatted HTML version, not plaintext XML)
setting browser.feeds.handler to "Reader" (this is an about:config alternative to above) or anything else. There's no plaintext option.
editing mimeTypes.rdf in one's profile folder - Firefox seems not to care about feed settings there
adding a new web content handler with URI view-source:%s - I think it was pretty close, but Firefox escapes the forwarded URL and refuses to open it
storeHtmlSource as it is too smart and does return the code of the formatted page, not the XML source

Firefox shows .gadget files in tab instead of downloading

I have a simple HTML file which references .gadget so that it can be downloaded:
Download me!
IE, Opera, Safari and Chrome all offer saving file to disk, however Firefox loads binary file in a tab. Why does Firefox hate me and what must I do to force Firefox to offer download dialog?
I don't really want to instruct users to "right-click and choose 'save file as'", or that they have to remove .zip extension after downloading.
Server is Apache/2.2.17, in case that it's relevant. Interesting fact is that Firefox does behave like all other browsers - if I load open .html file from local disk. But once it's on the server, it loads file in a tab.
So, here's the solution.
The problem is that Apache returns Content-Type=text/plain HTTP header by default for all "unknown" file types. Firefox adheres to the standards unlike all other browsers so it displays the content. Here's what they have to say about it. You can inspect header in Firefox with Firebug (or simply use curl if you're on Unix).
The above link also hints the solution; register application/x-windows-gadget MIME type with the server. If you don't have access to the server configuration, put .htaccess file in the same directory as your file (or in any of the directories above your directory) with the following line:
AddType application/x-windows-gadget .gadget
After that, don't forget to clear your browser cache.

Resources