What HTTP header is needed to be returned so web browsers use the suggested filename? (File download from CGI in C) - c

We have a PDF file download link on a web page with a C language CGI program actually passing on the file from our embedded device's web server. The web server is custom coded because of severe memory limitations.
The suggested filename by the C program is "Manual.pdf".
On Internet Explorer 8, when we click on the link the usual "Open/Save" box opens with the suggested filename displayed being "download.pdf" which is wrong. On Firefox, the suggested filename is "download.cgi" which is worse. However both browsers correctly indicate that the download is a PDF type.
Here are a few unrelated snippets of code to show the headers we are returning:
{ CONTENT_TYPE_PDF, "application/pdf\nContent-Disposition:attachment;" }
sprintf(tmpBuf, "Content-Type: %s\n", get_tbl_string((tbl_str_itm_t*)content_type, session->response.contenttype));
strcpy(tmpBuf, "filename=Manual.pdf\n");
strcat(tmpBuf, "Cache-Control: no-cache, no-store\n");
Can anyone tell what we are doing wrong?
Any help greatly appreciated.
Best regards,
Bert

The "filename" stuff is part of the content-disposition header.

Content-Disposition: attachment; filename=Manual.pdf header is good solution, however it doesn't work well if your filename has non-english characters. Another solution is to append "/Manual.pdf" path to your cgi script, i.e. use URLs like: http://server/path/my.cgi/Manual.pdf, and then your my.cgi program will be called with PATH_INFO=/Manual.pdf. For funky filenames, this works better than Content-Disposition header.
Update: If you are interested in browser support for Content-Disposition header, check http://greenbytes.de/tech/tc2231/.
Update: Another interesting article on the topic: Link

You might find some of the tips here useful:
http://blog.httpwatch.com/2010/03/24/four-tips-for-setting-up-http-file-downloads/

Related

Compress file to tgz with apache camel

I want to compress a file to ".tgz" extension using apache camel 3.11.1.
As the gzip format is not supported, I tried GZipDeflater data format but it is not working (the file remains unchanged).
I found a solution, maybe it can help someone else.
The solution was to use gzipDeflater DataFormat, and explicitly provide the extension in the file endpoint when producing the result:
from("file:...../in?noop=true")
.marshal().gzipDeflater()
.to("....../out1?fileName=${file:name.noext}.tgz");

File download problem in WildFly 18.0.0 - response headers missing

I have updated my WildFly server from 10.1 to 18.0.0.
Now I'm facing wired issue while download PDF as well as XLSX or any file larger than 15kb.
Say for example,
if I try to download XLSX file of size 100kb,
I find some headers (like - Content-Type, Content-Length, Content-Disposition, etc.) missing from response object although I set those explicitily from my application while writing file in response output stream. As a result the file is getting downloaded of uknown format.
But if I try to download XLSX file of size less than 16kb, the file is getting downloaded in correct format will all response headers present as I set.
I know it's too wired and parhaps this question seems silly or owakward but let me assure you that everything was good until we had older WildFly 10.1.
Can anyone give an idea what could be the reason?
Thanks
Jeet

How to start the actual "Speech to text"?

I am a freelancing author and have gathered tons of hours of interview material which needs to be transcribed.
While browsing the Internet I came across IBM Watson "Speech to text" which should be the ideal solution to handle that huge amount of spoken word.
After registration I am struggling with even opening it. Since I am not very much equipped with programming, etc.
Can someone provide an example with steps that I can follow to achieve my task?
which platform you want to use Speech to text service on it ?
If you are not a coder, then the best starting point for you will be Node-RED. Take a look at this tutorial that creates a translator - https://developer.ibm.com/tutorials/build-universal-translator-nodered-watson-ai-services/?cm_mmc=IBMDev--Digest--ENews2019-_-email&spMailingID=39408813&spUserID=MzYzODEwODAwNzk4S0&spJobID=1500992192&spReportId=MTUwMDk5MjE5MgS2
If uses Speech to Text, Translation, and Text to Speech. You will only need the Speech to Text bit. Once you get it working with a microphone you can make use of the file inject to push your own audio files through the service.
For larger files you will need to make use of http post and multi-parts, when you get to that point, raise a new question, tag it with node-red and someone will post a sample flow for you.
You do not need to have any programming knowledge to use Watson Speech To Text. You can just send your files to the service using the curl tool. Which you can easily install in your computer, it is free.
Then you can send a file to the service running the following command:
curl -X POST -u "apikey:{apikey}" --header "Content-Type: audio/flac" --data-binary #audio-file2.flac "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize"
You just need an apikey to run that command, which you can get following these steps: https://cloud.ibm.com/docs/services/watson?topic=watson-iam
Then just replace the .flac file in that command by the file you want to process. And pass the right value for the Content-Type: header. For Flac files it is audio/flac, for other audio formats you have the list here: https://cloud.ibm.com/apidocs/speech-to-text

How to download any file using selenium webdriver.

How to download any file using selenium webdriver.what is the logic to download any file in selenium webdriver
If you mean "any" file that browser would show, i.e. any html file, you just need to call
driver.getPageSource();
If you mean "any" file as in the "save link as" or similar menu of browsers you are out of luck, since this triggers the OS-driven download file chooser of a browser which can't be controlled by Selenium webdriver.
Solution to 2.
You have two options here I think:
a) use something like AutoIT ontop of selenium. This becomes very hard to control in a short time, is not portable and will make your tests error prone.
b) The better solution is probably to download the file outside of selenium. I found a nice article describing the whole dilemma here. It also contains a nice solution to the problem that takes even care of cookie-handling if needed for the download.
Actually it's not a good idea to download files using web-driver. I don't think that you need the file; in most cases, it's just for testing download links and for this purpose you can use driver.find_element_by_tag_name("a"), driver.find_elements_by_link_text("some text") or driver.find_elements_by_partial_link_text("a"); after finding the element, you just click() on it and check if the response's URL is actually what it should be.
Still if you have a goal for completely downloading the file, I'd be glad if you let me know.
EDIT:
Today, I visit this page and I think this will help you, specially this comment.

IE6 "helpfully" appends suffix to downloaded file

A webapp I've been developing allows users to upload and download a type of file which is meant to be treated as an opaque blob. My app serves it up with a file extension not commonly used for any other purpose, as well as specifying that its MIME Content-Type is application/octet-stream.
Internally, the file is a simple Zip archive containing a single compressed file. What I've found is that IE6 apparently inspects the content of the file, determines that it's a Zip archive, and "helpfully" saves it with an additional ".zip" extension. Unbelievable!
As I mentioned, this file is meant to be opaque, and we don't want users to be poking around inside the file--not because it's dangerous or contains sensitive information or anything, we just don't want to confuse them. I suggested prepending the Zip content with a magic number to prevent IE6 from recognizing it, but my manager says he'd prefer it if the file content could remain unchanged, so that knowledgeable people can rename the file and examine its contents as a zip archive, if necessary.
Is there any way to tell IE6 to keep its mitts off of the file? Or any alternative approach at all? (Alas, just not supporting IE6 at all is not an option.)
Incidentally, IE7 respects the file's name, but still identifies it as a Zip archive in the download dialog. That's better than IE6, but still less than ideal.
Short answer: Add correct MIME types to you web server so IE6 doesn't guess the file type.
Long Answer:
My work had a similar problem with Microsoft PowerPoint files.
.ppt vs .pps - Which are identical files with different extensions. We wanted the user to view a show (.pps) but IE6 kept changing it to .ppt. It changed the extention because the users machine had PowerPoint installed and understood that the file "looked" like a . ppt. Don't understand why not .pps.
The problem, besides IE6, was that our web server (IIS) was not aware of either MIME types for .pps or .ppt. So we had to add the correct MIME types so the server would not deliver them as "application/octet-stream". I understand that by using "application/octet-stream" IE6 will try to guess the MIME type.
So we added:
.pps = "application/vnd.ms-powerpoint"
.ppt = "application/vnd.ms-powerpoint"
Now it works fine with IE6.
I hope this helps solve your problem.
use this header flag: Content-Disposition: attachment; filename="yourfilename.extension"
This is a known problem, and the only solution is to edit the client computer's registry, which I'm sure doesn't help you a lot.

Resources