Text files uploaded to S3 are encoded strangely?

后端 未结 7 1012
醉话见心
醉话见心 2021-01-03 19:05

This is the strangest error, and I don\'t even know where to start understanding what\'s wrong.

S3 has been working well, up until suddenly one day (yesterday) it st

相关标签:
7条回答
  • 2021-01-03 19:27

    Not sure why, but the answer from Sony Kadavan didn't work in my case.

    Rather than:

    Content-Type: text/plain; charset=utf-8

    I used:

    Content-Type: text/html; charset=utf-8

    Which seemed to work.

    0 讨论(0)
  • 2021-01-03 19:32

    I had the same problem and I solved it by adding charset=utf-8 in properties -> metadata of the file

    0 讨论(0)
  • 2021-01-03 19:33

    In my problem I got the problem with reading file form the filesystem as UFT8 too,, so I got the wrong file encoding in s3 until I have added

    InputStreamReader isr = new InputStreamReader(fileInputStream, "UTF8");
    

    instead of

    InputStreamReader isr = new InputStreamReader(fileInputStream);
    

    please note of this possible problem too

    0 讨论(0)
  • 2021-01-03 19:41

    You can explicitly set the "Content-Type: text/plain; charset=utf-8", on the file in the S3 console.

    This will tell S3 to serve as text.

    0 讨论(0)
  • 2021-01-03 19:42

    Adding <meta charset="utf-8" /> in the <head> of the .html files fixed the problem for me.

    0 讨论(0)
  • 2021-01-03 19:46

    For those who are using boto3 (python 3) to upload and are having strange characters instead of accentuation (such as in portuguese and french languages, for example), Toni Chaz's and Sony Kadavan's answers gave me the hint to fix. Adding ";charset=utf-8" to ContentType argument when calling put_object was enough to the accentuation be shown correctly.

    content_type="text/plain;charset=utf-8"
    bucket_obj.put_object(Key=key, Body=data, ContentType=content_type)
    
    0 讨论(0)
提交回复
热议问题