use of HTTP Content-Disposition - content-disposition

I have this code:
resp.addHeader("Content-Disposition", "inline; filename=" + fileName);
When the file name is a_b_c.doc or abc.doc the name of the downloaded file is displayed correctly.
However, when the file name is a b c .doc the name of the downloaded file is only a.
How can we work around this?

Quote the filename: "filename.doc".

You always MUST quote the filename anyway. See §19.5.1 "Content-Disposition" in RFC 2616 Section 19 and $2.2 "Basic Rules" RFC 2616 Section 2 which defines "quoted-string".

Related

Why doesn't weblate recognize my pot file?

I'm using a hosted weblate.
I'm in the "Files" section of my component configuration.
Below is my setup.
Translation files:
File format: gettext PO file
Filemask: src/translations/*.po
Language filter: ^[^.]+$
Monolingual translations:
All fields empty
Edit base file checked
Adding new languages:
Template for new translations: src/translations/template.pot
Adding new translation: Create new language file
Language code style: Default based on the file format
I can't validate these settings, I have an error below fields "Template for new translations" and "Adding new translation":
The error is "Unrecognized base file for new translations".
I'm am 100% sure the pot file exists on the branch weblate is configured to use and also on master and that the path is correct.
Here are the first few lines of the pot file:
"Content-Type: text/plain; charset=UTF-8\n"
#: src/screens/CardList/CardList.texts.js:9
msgctxt "CardList"
msgid "hello"
msgstr ""
#: src/screens/CardList/CardList.texts.js:11
msgctxt "CardList"
msgid "cards"
msgstr ""
I don't understand what is happening, am I doing something wrong ?
The header of the file seems stripped. At least you should prepend following to make it syntactically valid:
msgid ""
msgstr ""
See https://github.com/WeblateOrg/weblate/blob/master/weblate/locale/django.pot for real life POT file

How to create and set content type in Vcard generate file in PHP

I have been working to generate vcard file in php just simple way.
my code like following :
header('Content-Type: text/x-vcard;charset=utf-8;');
header('Content-Disposition: inline; filename= "'.$file.'"');
header("Pragma: no-cache");
and generated file is something like this:
BEGIN:VCARD
FN:Elke Schöne;
ADR;INTL;HOME:;;;Leipziger Straße 3;Markranstädt;04420;
EMAIL;INTERNET:praxis.elkeschoene#t-online.de
TEL;FAX;HOME:+49 34205 83980
TEL;HOME:+49 34205 88249
URL;WORK:www.praxis-schoene.de
REV:20161207
END:VCARD
But when i open this file in Windows Contact then name "Schöne" is not encoded and display with special character, but it works fine in Thunderbird contact.
can anybody help me..
You can add the charset:
FN;CHARSET=Windows-1252:Elke Schöne
The semi colon at the end of the lines is not needed on vcard.

cfdirectory replacing spaces with + characters when action=list on an S3 folder

I am uploading a file, that contains spaces in the name, to Amazon S3 using cffile action="upload". The file name is burger+beans n beetroot.jpg.
As you can see, the name contains spaces and a plus sign.
When I read the directory, to list the contents, the file name returned by ColdFusion in the query is: burger+beans+n+beetroot.jpg. However, when viewing the file using Amazon S3 Browser, it is correctly listed as: burger+beans n beetroot.jpg. So it appears ColdFusion is replacing the spaces with + signs.
Does anyone know why this happens and if there is a way to disable this? I tried using both the DirectoryList() method as well as the <cfdirectory action="list"> tag, and both do this.
Please note: I am aware that the file name could be cleaned up before processing - that's a workaround, but not the solution I am looking for. Thanks!
I believe this is not a CF problem, it's a S3 problem. They send out their file names escaped. Which makes this a non-answer.
I created a folder in a S3 bucket. Then I uploaded a file named burger+beans n beetroot.jpg. I can see in AWS' console the file properly named. I select it, then in the Actions menu select Download. I get the modal window. Take a look at the URL in the browser footer - the file name is escaped.
I right-click their link and choose "Save Link As..." - the file name is escaped as well.
So I don't think there is anything you can do once the file is up there. You'll need to clean it before uploading. I know it's not what you want to hear.
Try URL encoding the filename, so the + sign will be converted to an url encoded space (%2b). You could use URLEncodedFormat, but make sure that the path to the file isn't urlencoded as well.

How can I determine if a file upload is a valid CSV file - or at least text - in ColdFusion 8?

I have a form which allows a user to upload a file to the server. How can I validate that the uploaded file is in fact the expected format (CSV, or at least validate that it is a text file) in ColdFusion 8?
For simple formats like CSV, just check yourself, for example via regex.
<cffile action="read" file="#uploadedFile#" variable="contents" charset="UTF-8">
<cfset LooksLikeCSV = REFind("^([^;]*;)+[^;]*$", contents)>
You can place additional checks with regard to file size limits or forbidden characters.
For other file formats, you can check for header signatures that occur in the first few bytes of the file.
You could even write a full parser for your expected file format - for CSV validation, you could do a ListToArray() at CR/LF and check each line individually against a regex. XML should work pretty straightforward as well - just try to pass it to XmlParse(). Binary formats like images are a little more difficult, but libraries exist there as well.
I dont know if it can help you but Ben Nadel wrote excellents posts about CSV:
http://www.bennadel.com/blog/483-Parsing-CSV-Data-Using-ColdFusion.htm
http://www.bennadel.com/blog/976-Regular-Expressions-Make-CSV-Parsing-In-ColdFusion-So-Much-Easier-And-Faster-.htm
http://www.bennadel.com/blog/501-Parsing-CSV-Values-In-To-A-ColdFusion-Query.htm
I think it's as simple as specifying the accept value in cffile ...Unfortunately the CF8 docs don't specify the value as part of the info for cffile ... It's under file management ...
<cffile action=”upload” filefield=”filename” destination=”#destination#” accept=”text/csv”>
CF8 » Controlling the type of file uploaded

Error while downloading file with "." in name in RoR3

When I download a file that contains "." in its name my code throws an exception:
No route matches "/test/download/File%201.0%20BETA.docx"
The file name is: "File 1.0 BETA.docx"
Here is my code for downloading file in my controller file:
def download
path = params[:path]
path = "#{Rails.root}/public/data/" + path
send_file(path+"."+params[:format])
end
How can I solve it?
This is most likely caused by your routes not supporting multiple "." in the path. For example, if your routes look like this:
'/test/download/:path.:extension'
Then that will break if the filename contains more then one "."
Instead you could do a routing like this:
'/test/download/*path.:extension'
That will make sure that multiple "." is functioning