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

Can we support DownloadFileFromText with charset parameter or by default supporting special characters #22

Closed
stevanuswijaya opened this issue Jan 11, 2021 · 21 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers invalid This doesn't seem right

Comments

@stevanuswijaya
Copy link

Can we support DownloadFileFromText with charset parameter or by default supporting special characters? I'm currently trying to create a CSV file with Swedish characters in it (ÄÅÖäåö).

But the result is wrong:

image

It's working if I added the code as in the image.

image

Thanks

@arivera12
Copy link
Owner

arivera12 commented Jan 12, 2021

Seems weird to me, the DownloadFileFromText should be able to support all characters since it's utf-8 but not every charset maybe in the same encoding format when reading from any source.

As you can see this extension method

public static string ToBase64Encode(this string plainText)

Encodes all text to bytes using utf8, are you sure your problem exactly or may reside over there?

I don't think this should be a JavaScript issue at all but maybe from c# encoding since JavaScript downloads the file as-is without any encoding or conversions.

If you can send me a repro I may fix it.

Can you confirm that before sending the text to the DownloadFileFromText method the text is correctly encoded and they get interpreted incorrectly after downloading and opening the file?

@arivera12
Copy link
Owner

That error can also occur with the text editor and how does it's interprets the characters.

What software you are using to open the csv file? MS Excel?

@arivera12 arivera12 self-assigned this Jan 14, 2021
@arivera12 arivera12 added the invalid This doesn't seem right label Jan 14, 2021
@stevanuswijaya
Copy link
Author

As you can see here, when I call BlazorDownloadFile, the string was still okay.

image

I'm using MS Excel to open the csv file.

@arivera12
Copy link
Owner

Ok, good can you check which charset enconding is your MS Excel opening the csv file?

@arivera12
Copy link
Owner

Can you check if the .csv file opened in notepad to see if it's encoded wrongly?

@arivera12
Copy link
Owner

Can you check if the .csv file opened in notepad to see if it's encoded wrongly?

If opened in notepad is wrong then I will expose the charset encoding as an option with a default value to prevent breaking changes on the api.

Please let me know asap.

@arivera12
Copy link
Owner

arivera12 commented Jan 14, 2021

I would like also to know if after using the extension to base64encode does your encoding gets broken.

@stevanuswijaya
Copy link
Author

I opened the bad the file with notepad++.

image

The encoding: UTF-8
image

But in excel:

image

The good file after changing the BlazorDownloadFile script in notepad++:
image

Encoding: UTF8-BOM
image

In excel:

image

@stevanuswijaya
Copy link
Author

I tried to change the base64encode this code instead as you instructed

image

and we still get same bad result

image

@arivera12 arivera12 added the bug Something isn't working label Jan 15, 2021
@arivera12
Copy link
Owner

Thanks for the investigation and the input I will take a deeper look on it.

Can you share any sample data for me in json format?

So I can use it has a test case?

@arivera12
Copy link
Owner

arivera12 commented Jan 15, 2021

Wait a minute I read this in a hurry, in notepad++ the file opened ok. But in excel is wrong but after changing the encoding file format in notepad++ the excel read ok?

@arivera12
Copy link
Owner

This seems to be an issue with excel on how interprets csv filed but not rather with this library and the download process.

Reference:
https://stackoverflow.com/questions/6002256/is-it-possible-to-force-excel-recognize-utf-8-csv-files-automatically

@arivera12
Copy link
Owner

Please upload for me a test json data so I can retest those special chars there seems to be a workaround this in the reference link.

@arivera12 arivera12 added enhancement New feature or request and removed bug Something isn't working labels Jan 15, 2021
@stevanuswijaya
Copy link
Author

stevanuswijaya commented Jan 18, 2021

Here is the test json, I had same issue with it. Let me know if you need more information.
test data.zip

Sorry for late reply, I think we have a huge time difference and I was really busy at work :)

@arivera12
Copy link
Owner

arivera12 commented Jan 20, 2021

New release
Install-Package BlazorDownloadFile -Version 2.1.4

@stevanuswijaya I didn't had time to test your attached file data but it should work for you out of the box.

I am in a hurry.

Please try out this new package version.

Take a look of this commit for more details.

I turned on by default encoderShouldEmitUTF8Identifier so this should work for you out of the box.

Please try it out and give me your feedback when ever it's possible.

@stevanuswijaya
Copy link
Author

Hi

Unfortunately, I still got same problem.

image

@arivera12
Copy link
Owner

Ok, give me a time so I can retest this with more free time, reopening.

@arivera12
Copy link
Owner

It's seems I got it working now.
image

@arivera12
Copy link
Owner

Install-Package BlazorDownloadFile -Version 2.1.5

Please give me feedback if this does work for you properly now!

@arivera12
Copy link
Owner

Install-Package BlazorDownloadFile -Version 2.1.6

encoderShouldEmitUTF8Identifier is now false as default please remember turning this option true when downloading the csv file.

@arivera12 arivera12 added the good first issue Good for newcomers label Jan 20, 2021
@stevanuswijaya
Copy link
Author

stevanuswijaya commented Jan 21, 2021

It's working properly now! Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants