Skip to content

Commit 90426ee

Browse files
committed
fix encoding for text file
1 parent 7ba3748 commit 90426ee

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

info.plist

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,16 +384,16 @@
384384
</dict>
385385
<key>variablesdontexport</key>
386386
<array>
387-
<string>cf_secret_key</string>
388-
<string>tinypng_api_key</string>
389-
<string>cf_bucket_name</string>
390387
<string>cf_account_id</string>
388+
<string>cf_bucket_name</string>
391389
<string>cf_access_key</string>
392390
<string>shorturl</string>
391+
<string>tinypng_api_key</string>
393392
<string>cf_region</string>
393+
<string>cf_secret_key</string>
394394
</array>
395395
<key>version</key>
396-
<string>1.1</string>
396+
<string>1.2</string>
397397
<key>webaddress</key>
398398
<string>https://github.com/patelutkarsh</string>
399399
</dict>

upload-s3.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def capture_text(extension):
2525
file_path = os.path.join(tempfile.mkdtemp(), file_name)
2626
with open(file_path, "wb") as f:
2727
f.write(text_file)
28+
2829
# return content type based on extension.
2930
content_type = mimetypes.MimeTypes().guess_type(file_path)[0]
3031
return file_path, file_name, content_type
@@ -77,7 +78,12 @@ def main(wf):
7778
endpoint_url="https://%s.r2.cloudflarestorage.com/%s" %(account_id, bucket_name),
7879
region_name=region_name
7980
)
80-
s3.upload_file(file_path, bucket_name, file_name, ExtraArgs={'ContentType': content_type})
81+
# Set explicit content type with UTF-8 encoding for text files
82+
extra_args = {'ContentType': content_type}
83+
if content_type and content_type.startswith('text/'):
84+
extra_args['ContentType'] = content_type + '; charset=utf-8'
85+
86+
s3.upload_file(file_path, bucket_name, file_name, ExtraArgs=extra_args)
8187
shorturl = os.getenv('shorturl')
8288
# if short url is not empty and exists.
8389
if shorturl:

0 commit comments

Comments
 (0)