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

CSV Imports don't work in certain scenarios due to specific content type requirements #19

Closed
jawood1 opened this issue Nov 21, 2023 · 7 comments
Labels
type/bug Something isn't working

Comments

@jawood1
Copy link
Contributor

jawood1 commented Nov 21, 2023

Which version of Skybrud.Umbraco.Redirects.Import are you using? (Please write the exact version, example: 4.0.1)

4.0.1

Which version of Skybrud.Umbraco.Redirects are you using? (Please write the exact version, example: 4.0.15)

4.0.17

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

10.7.0

Bug description

When uploading a csv file there is a conditional check for the content type which checks it is "text/csv" in the CsvImporter file.

However, I noticed that in most cases the validation was failing due to the content type differing from "text/csv".

Further digging further it seems common types that are used for CSVs are:

  • text/csv
  • application/vnd.ms-excel

But this could also extend to:

  • text/plain
  • application/vnd.ms-excel
  • text/x-csv
  • application/csv
  • application/x-csv
  • text/comma-separated-values
  • text/x-comma-separated-values
  • text/tab-separated-values

I'm happy to raise a PR that includes validation for the below content types as these seem to be the most common or I can extend to also include the other types but I haven't tested these:

  • text/csv
  • application/vnd.ms-excel
@abjerner
Copy link
Member

abjerner commented Dec 7, 2023

Hi @jawood1

Can you elaborate about in which cases you've experienced that the content type isn't text/csv? I haven't come across this, but I'd imagine different browsers and OSs could provide different content types.

@jawood1
Copy link
Contributor Author

jawood1 commented Dec 8, 2023

Hi @abjerner

I noticed I get the application/vnd.ms-excel when saving a CSV through excel or by having my default program to open the file as excel.

I first noticed the issue as the CSV import kept failing as it was saying it wasn't a CSV. So when diving into the code I found on upload it would return application/vnd.ms-excel as the content type even though my extension was a .csv.

I'm currently working on Windows 11, but I've also seen information that for instance Apple users get text/plain as their content type for instance?

So I believe it does vary for different devices and browsers.

https://stackoverflow.com/a/42140178 - I found this post that outlines some of the common types they've found.

https://stackoverflow.com/questions/5351093/what-is-the-meaning-of-vnd-in-mime-types/5351162 - this thread is also interesting. It seems that:

  • x- are content types that are non standard
  • vnd are content types introduced by corporate bodies rather than as a standard.

So though text/csv is the correct standard others can still apply.

More than I ever thought I'd learn about content types XD

@abjerner
Copy link
Member

abjerner commented Jan 3, 2024

Hi @jawood1

I cant really say for Apple based systems, but I can't reproduce any issues on Windows 10 and 11. In both cases, I have .csv associated with Excel, but still the mime type comes up as text/csv.

image

Generally application/vnd.ms-excel should be used for .xls files, not .csv.

Can you share how .csv files are associated in your Windows setup?

@jawood1
Copy link
Contributor Author

jawood1 commented Jan 4, 2024

Hi @abjerner

My CSV files were associated with Excel like yourself.

Oddly I don't seem to be able to re-create the issue now since I've had my work laptop rebuilt at the end of last year.

Though it was definitely was the case for myself before hand that application/vnd.ms-excel was the content type being seen when:

  • Creating a CSV within Excel
  • Creating a CSV outside of Excel
  • Converting a Excel Spreadsheet to CSV

Perhaps it was some issue with my machine or some weird edge case?

@abjerner
Copy link
Member

abjerner commented Jan 4, 2024

@jawood1 thanks for the reply 👍

My guess is that your file association has been wrong on your old system then. I'll try doing some more research as I'm also not sure what Apple based systems report as the content type for CSV files. Ideally they should also report text/css, but if they widely report text/plain instead, it could possibly make sense to include this content type as well. Or make the content types configurable.

@jawood1
Copy link
Contributor Author

jawood1 commented Jan 4, 2024

Great stuff, I think it could be a good solution perhaps to have configurable content-types for edge cases like this.

I found an additional source here that states some of primary content-types used, however it doesn't mention text/plain or application/vnd.ms-excel.

https://www.digipres.org/formats/sources/ffw/formats/#csv

In the case of Apple devices it seems text/plain may occur due to how the files are formatted from what I've seen, but I can't verify if that's a theme in Apple devices or if it's another edge case scenario.

Update:
Interesting article on CSV validation issues
https://christianwood.net/posts/csv-file-upload-validation/#tldr

abjerner added a commit that referenced this issue Jan 6, 2024
@abjerner
Copy link
Member

abjerner commented Jan 6, 2024

Closing this issue as the content types should now have been addressed by dcf7e98

@abjerner abjerner closed this as completed Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants