Lokus Pokus
Lokus Pokus

Reputation: 305

Remove file extensions with gsutil

Is there any way to remove file extensions when copying files with gsutil?

From local 0001:
 0001/a/1.jpg
 0001/b/2.png

To bucket 0002:
 gs://0002/a/1
 gs://0002/b/2

(I can remove the extensions locally but I will be losing the Content-Type when copying to GS)

Upvotes: 2

Views: 892

Answers (1)

Mike Schwartz
Mike Schwartz

Reputation: 12145

gsutil doesn't have any mechanism for rewriting the file name in this way. You could write a shell loop that iterates over the files and removes the extensions in the file names being copied.

To preserve the Content-Type here are a couple of suggestions:

  1. Set it explicitly on the command line, e.g.,

    gsutil -h Content-Type:image/jpeg cp 0001/a/1.jpg gs://0001/a/1

  2. Use the use_magicfile configuration (in the .boto config file), to cause the Content-Type to be detected by the "file" command. This only works if you're running on Unix or MacOS. In this case you'd still use the shell script to remove the filename extensions, but you wouldn't have to specify the -h Content-Type arg:

    gsutil cp 0001/a/1.jpg gs://0001/a/1

Mike

Upvotes: 3

Related Questions