Filepond: Filename incorrectly parsed from Content-Disposition header

Created on 18 Jun 2018  ·  12Comments  ·  Source: pqina/filepond

First of all — awesome plugin 👍

We use Amazon S3 for file storage, and the Content-Disposition header includes both the filename and filename* directives:

Content-Disposition: inline; filename="airplane.png"; filename*=UTF-8''airplane.png

Which displays like so in FilePond:

image

A potential fix could be to explicitly search for the filename="" directive using a regular expression:

const getFilenameFromHeaders = headers => {
  const rows = headers.split('\n');
  for (const header of rows) {
    const match = header.match(/filename="(.*)"/)
    if (!match) {
      continue;
    }
    return match[1].replace(/["']+/g, '');
  }
  return null;
};

Happy to submit a pull request if you'd prefer that. Thanks!

All 12 comments

Thanks for reporting ( and the suggested fix )! It's certainly an odd looking header with the * and the single quotes in there.

Just updated the code ( seen snippet below ) and pushed version 1.7.4

export const getFilenameFromHeaders = headers => {
    const rows = headers.split('\n');
    for (const header of rows) {
        const matches = header.match(/filename="(.+)"/);
        if (!matches || !matches[1]) {
            continue;
        }
        return matches[1];
    }
    return null;
};

@kylefox Can you confirm this solved the issue?

Will close for now. If not resolved, I'll re-open.

Works perfectly 👍Thanks for the quick response!

I am using v4.4.0:
"filepond": "^4.4.0",
"filepond-plugin-file-metadata": "^1.0.6",
"filepond-plugin-image-preview": "^4.0.8",
and it is still an issue. See screenshot

I am using v4.4.0:
"filepond": "^4.4.0",
"filepond-plugin-file-metadata": "^1.0.6",
"filepond-plugin-image-preview": "^4.0.8",
and it is still an issue. See screenshot

Same in v4.3.9

Please paste the content disposition header of the response so I can try to reproduce the issue.

Header:
Content-Disposition: attachment; filename=Invoker.jpg; filename*=UTF-8''Invoker.jpg

It is generated by asp.net mvc core 2.2:
return File(file.Content, "image/jpg", file.Filename);

I have implemented workaround for this:
Response.Headers.Add("Content-Disposition", $"inline; filename=\"{file.Filename}\""); return File(file.Content, "image/jpg");

@dnknitro @petrama I've confirmed the issue and will probably roll out a fix next week.

Fixed in 4.4.1

I have just tried the fix and filename with spaces (or probably any other url encoded characters) are still displayed incorrectly.
Header: Content-Disposition: attachment; filename="wp SecretaryBird 1920x1200.jpg"; filename*=UTF-8''wp%20SecretaryBird%201920x1200.jpg
Filename displayed: wp%20SecretaryBird%201920x1200.jpg

@dnknitro I've added this as a test case and now it should be fixed in 4.4.2

Works now, thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Strenget picture Strenget  ·  6Comments

enisdenjo picture enisdenjo  ·  6Comments

mrsamse picture mrsamse  ·  6Comments

madrussa picture madrussa  ·  6Comments

oldrich-s picture oldrich-s  ·  5Comments