最近協助處理一個Google Cloud Storage的CLI工具遇到中文的問題
在CentOS的環境上,透過gsutil會有無法上傳的問題
狀況如下:
[simonsu@centos6 ~]$ gsutil mb gs://test-centos6-upload
Creating gs://test-centos6-upload/...
[simonsu@centos6 ~]$ vi 中文字母.txt
[simonsu@centos6 ~]$ vi 中文字母.txt
[simonsu@centos6 ~]$ ls -l
total 4
-rw-rw-r--. 1 simonsu simonsu 22 Mar 3 16:31 ????????????.txt
[simonsu@centos6 ~]$ vi 中文字母.txt
[simonsu@centos6 ~]$ mkdir test
[simonsu@centos6 ~]$ mv *.txt test/
[simonsu@centos6 ~]$ gsutil cp -R test/ gs://test-centos6-upload/
Failure: 'ascii' codec can't encode characters in position 5-8: ordinal not in range(128).
[simonsu@centos6 ~]$ gsutil cp -R test/中文字母.txt gs://test-centos6-upload/
Failure: 'ascii' codec can't encode characters in position 5-8: ordinal not in range(128).
[simonsu@centos6 ~]$
在Google Support跟Google Search的協助下
最後終於解決
原來是Linux的Encoding
在修改/etc/sysconfug/i18n為下面內容後
LANG="zh_TW.UTF-8"
LC_CTYPE="zh_TW.UTF-8"
SUPPORTED="zh_TW.UTF-8:zh_TW.BIG5:zh_TW:zh:en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"
重新確認參數是否生效(可以使用echo $[變數名稱])
如果上述四個參數都沒問題
原則上就可以看到中文字
gsutil也就可以正常上傳了唷 :D
留言
張貼留言