Closed tusbar closed 7 years ago
0.6 build breaks, and the log (>4MB) is useless. But who uses node 0.6.
Hi @tusbar thanks for the pull request! Unfortunately I do not think this is the correct way to approach this use-case. You see, what Azure is doing is encoding the file name as RFC 2047 and then taking that string and setting it as the file name in the Content-Disposition header. To Content-Disposition parsers (like this module) the file name itself is opaque; just like this would not automatically un-base64-encode the filename just because it happened to be a base64 string as the filename field.
Instead, you need to first parse the header, then given the knowledge that you are getting a response from Azure and they pass a RFC 2047 string as the file name, decode the filename.
Here is an example module:
var contentDisposition = require('content-disposition')
module.exports = function getFilename (header) {
return rfc2047decode(contentDisposition.parse(header).parameters.filename)
}
Hi @dougwilson, yeah, that makes sense. At least it made me understand how to deal with that particular case. Thanks.
Handle both Q(uoted) and B(ase64) encodings.
This allows to extract filenames from headers such as
attachment; filename="=?utf-8?B?TGVzIGPDomJsZXMgb3B0aXF1ZXMuemlw?="
that are returned today by Azure Storage.