Skip to content

Instantly share code, notes, and snippets.

@akamola
Last active July 23, 2022 05:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akamola/3948a8c9bad29149d155559f01b8c44c to your computer and use it in GitHub Desktop.
Save akamola/3948a8c9bad29149d155559f01b8c44c to your computer and use it in GitHub Desktop.
Unity3D WebGL + AWS S3: Set correct content-type and content-encoding
#!/usr/bin/env python3
# coding: utf-8
# Sets the correct content-type and content-encoding for Unity3D files.
# @see https://forum.unity.com/threads/changes-to-the-webgl-loader-and-templates-introduced-in-unity-2020-1.817698/#post-5716621
import boto3
bucket_id = 'unity-model'
folder_prefix = 'model'
# Configure files and content-types
unity_objs = [
{
'key': folder_prefix + '/Build/model.data.gz',
'content_type' : 'application/octet-stream'
},
{
'key': folder_prefix + '/Build/model.framework.js.gz',
'content_type' : 'application/javascript'
},
{
'key': folder_prefix + '/Build/model.wasm.gz',
'content_type' : 'application/wasm'
},
]
# Connect to S3
s3 = boto3.resource( 's3' )
# Set meta data
for obj in unity_objs :
s3_obj = s3.Object( bucket_id, obj['key'] )
try :
response = s3_obj.copy_from( CopySource={ 'Bucket' : bucket_id,
'Key' : obj['key'] },
ContentType=obj['content_type'],
ContentEncoding='gzip',
MetadataDirective='REPLACE' )
if ( response['ResponseMetadata']['HTTPStatusCode'] == 200 ) :
print( 'SUCCESS - ' + obj['key'] )
else :
print( 'ERROR - ' + obj['key'] )
except :
print( 'ERROR - ' + obj['key'] )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment