When I try to upload images to a bucket, it throw an error "Invalid bucket name "thum.images ": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$""
.
I think there is nothing wrong with a bucket name.
This is my code to upload image:
def upload_thumbnail_image(image_key, thumbnail_image):
thumbnail_image_bucket = os.environ['thumbnail_bucket']
thumbnail_image = #image path
image_key = EFE3-27C8-EEB3-4987/3612d0bc-bdfd-49de-82ee-3e66cbb06807.jpg
try:
new_object = client.upload_file(thumbnail_image, thumbnail_image_bucket, image_key)
return new_object
except Exception as Exc:
set_log(Exc.args[0],True)
The "Invalid bucket name "thum.images ": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$""
error means just what it says: the bucket name must contain some typo or is just wrong as it should meet the following pattern:
^
- start of string[a-zA-Z0-9.\-_]{1,255}
- 1 to 255 ASCII letters, digits, dots, -
or _
chars$
- end of string.You may test your bucket names online here.
There can be no whitespaces in the bucket name.
I often get this error because an extra slash gets into the bucket name after I copy/paste the bucket name from the S3 Web page, like aws s3 sync s3:///my-bucket/folder folder
, where instead of the triple backslashes there must be just two.
I received this error because I had an invisible non-printing character (the BOM, aka Byte Order Mark, aka U+FEFF) at the beginning of an csv file that contained the s3 path. I was able to find it with this python code:
print(":".join("{:02x}".format(ord(c)) for c in s3_path))
which resulted in feff:
... at the beginning of the string which tipped me off. You would expect to see output like 6d:79:2d:70:61:74:68
(i.e. two digit hex numbers).
(Update 2022) As per the comment from Ben Allred, there are other non-printing characters that could also cause the same error and be difficult to detect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With