Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import csv containing html link errors #22

Open
flamerohr opened this issue Apr 27, 2016 · 4 comments
Open

import csv containing html link errors #22

flamerohr opened this issue Apr 27, 2016 · 4 comments

Comments

@flamerohr
Copy link

Hi, I've got a csv file which contain html content. Most import fine, except for when the html contain <a href="http://example.com">Click here</a>
When that happens, I get returned the error File extension does not match known MIME type

@tractorcow
Copy link

The problem this is caused by is HTML content within CSV causing the file to be mis-classified by the mime validator.

A possible fix for this is to allow file extensions to declare they allow wildcard mime types, so that text/* can be assigned to extensions for known plain-text types (e.g. CSV). This is necessary because specific matching of plain text file types to mimes is always going to be inprecise, and in most cases any mis-match would be within reasonably acceptable limits.

@NightJar
Copy link
Contributor

Is there an example CSV document that could be used for testing?
What kind of ratio of CSV:HTML are we talking here?
How 'correctly' formatted is the CSV? I mean, I know it's a bit of a 'flakey' non-standard as it is, but generally speaking...

@flamerohr
Copy link
Author

As long as the CSV contains any HTML, it would be considered an HTML file - rather than CSV.
If a small amount doesn't work, try push it to a 50% ratio of HTML

@fspringveldt
Copy link

fspringveldt commented Oct 14, 2020

I encountered this when a DataObject I exported to CSV using ModelAdmin contained a DBHTML field with HTML content.
Trying to re-import that file then silently fails and closes the Dialog. It's not until you click Import CSV again and the error is revealed

image

After digging I noticed that yes, indeed the mime-type was text/html and not text/plain as expected because of the presence of HTML.

Anyway, my workaround was to just allow it in config.

SilverStripe\MimeValidator\MimeUploadValidator:
  MimeTypes:
    csv:
      - 'text/html'
      - 'text/plain'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants