jakejarvis / s3-sync-action

🔄 GitHub Action to sync a directory with a remote S3 bucket 🧺
https://github.com/marketplace/actions/s3-sync
MIT License
1.03k stars 471 forks source link

Can you set Content-type="text/html" for file without extension? #40

Open o7w opened 4 years ago

o7w commented 4 years ago

I want use URL like this "http://example.com/abc" instead of "http://example.com/abc.html", Can you add an option to set Content-Type to text/html for files without extension?

lmcarreiro commented 3 years ago

I have a related problem... web assembly files (*.wasm extensions) need to use content-type application/wasm to avoid error on Google Chrome, but the current type being used is binary/octet-stream. Is there any way to replace the content-type of specific files?

zmays commented 3 years ago

looks like you can do that with the optional args flag

andre-lx commented 3 years ago

You can achieve this with the args flag as @zmays mentioned. As an example:

    - name: Deploy html files without extension and with content type
      uses: jakejarvis/s3-sync-action@master
      with:
        args: --acl public-read --follow-symlinks --delete --include '*' --exclude '*.*' --content-type text/html
      env:
        AWS_S3_BUCKET: ${{ env.BUCKET_NAME }}
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        AWS_REGION: 'eu-west-1'

This excludes all files with extension (something.some_extension), and upload all files without an extension (in this case, all files without the .html extension), and set the content-type to text/html for this files.

Since you can't upload all files with this content type (like js files), if you also want to upload all the other assets, you can upload all the files in another step and including all files with an extension:

    - name: Deploy all files
      uses: jakejarvis/s3-sync-action@master
      with:
        args: --acl public-read --follow-symlinks --include '*.*'
      env:
        AWS_S3_BUCKET: ${{ env.BUCKET_NAME }}
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        AWS_REGION: 'eu-west-1'