[C#] fix filename and Content-Disposition parsing on FileStream

This commit is contained in:
hacki11 2015-12-15 23:33:48 +01:00
parent 89f269969d
commit 322e7a4b4b

View File

@ -233,12 +233,15 @@ namespace {{packageName}}.Client
? Path.GetTempPath() ? Path.GetTempPath()
: Configuration.TempFolderPath; : Configuration.TempFolderPath;
var regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$"); var regex = new Regex(@"Content-Disposition:.*filename=['""]?([^'""\s]+)['""]?$");
var match = regex.Match(headers.ToString()); foreach (var header in headers)
if (match.Success)
{ {
string fileName = filePath + match.Value.Replace("\"", "").Replace("'", ""); var match = regex.Match(header.ToString());
File.WriteAllBytes(fileName, data); if (match.Success)
return new FileStream(fileName, FileMode.Open); {
string fileName = filePath + match.Groups[1].Value.Replace("\"", "").Replace("'", "");
File.WriteAllBytes(fileName, data);
return new FileStream(fileName, FileMode.Open);
}
} }
} }
var stream = new MemoryStream(data); var stream = new MemoryStream(data);