Martin Zeitler
Martin Zeitler

Reputation: 76579

How to set the content-type, when uploading to Cloud Storage bucket?

When uploading an *.tar.gz build artifact to Cloud Storage bucket, it wrongfully applies MIME type application/tar, while it would have to apply MIME type application/tar+gzip (or the official MIME type application/gzip), in order to be able to download and extract the uploaded *.tar.gz archive then again. This only works, when I manually set the MIME type afterwards (in the object details), but I'd be looking for a way, to define the proper MIME type right away. How this can be done?

The cloudbuild.yaml which produces the issue roughly looks alike this:

steps:
  - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:latest'
    entrypoint: 'bash'
    args:
      - '-c'
      - |-
      - tar -zcf ./test_${SHORT_SHA}.tar.gz ./$_UPLOAD_DIRNAME
    env:
      - '_UPLOAD_DIRNAME=$_UPLOAD_DIRNAME'
      - 'SHORT_SHA=$SHORT_SHA'
artifacts:
  objects:
    location: 'gs://some-bucket/'
    paths: ['*.tar.gz']

Upvotes: 1

Views: 2176

Answers (1)

Martin Zeitler
Martin Zeitler

Reputation: 76579

After reading: Working With Object Metadata, it turned out that the artifacts node won't suffice. gsutil seems to be the only way to explicitly pass the desired MIME type application/tar+gzip:

steps:
  - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:latest'
    entrypoint: 'bash'
    args:
      - '-c'
      - |-
        tar -zcf ./test_${SHORT_SHA}.tar.gz ./$_UPLOAD_DIRNAME
        gsutil -h "Content-Type:application/tar+gzip" cp ./test_${SHORT_SHA}.tar.gz ${_GOOGLE_STORAGE_BUCKET}
        gsutil ls -L ${_GOOGLE_STORAGE_BUCKET}test_${SHORT_SHA}.tar.gz
    env:
      - '_UPLOAD_DIRNAME=$_UPLOAD_DIRNAME'
      - '_GOOGLE_STORAGE_BUCKET=$_GOOGLE_STORAGE_BUCKET'
      - 'SHORT_SHA=$SHORT_SHA'

Upvotes: 2

Related Questions