Can't perform PutObject operation #738

Closed
opened 2024-02-29 11:49:38 +00:00 by ghashy · 2 comments

Thank you very much for garage! Previously, I was using minio with aws-sdk-s3 in Rust. Now, I am attempting to transition to garage, but my previous code that was working no longer functions correctly. In this code snippet, I am trying to upload a file to an S3 bucket named mustore-data with the key received/user1:886773de-cc58-4d2b-81bb-b4db05349817:avatar.png:

        let _put_response = self
            .client
            .put_object()
            .bucket(&self.settings.bucket_name)
            .key(key.as_ref())
            .content_encoding(mediatype.to_string())
            .body(
                ByteStream::try_from(SdkBody::from(bytes))
                    .context("Failed to create ByteStream from bytes")?,
            )
            .send()
            .await
            .context("Failed to upload file to the object storage")?;

However, the output I received indicates an error:

2024-02-29T11:40:32.826738Z  INFO garage_api::generic_server: [::ffff:192.168.215.0]:53406 HEAD /
2024-02-29T11:40:52.472320Z  INFO garage_api::generic_server: [::ffff:192.168.215.0]:53406 PUT /received/user1%3A886773de-cc58-4d2b-81bb-b4db05349817%3Aavatar.png?x-id=PutObject
2024-02-29T11:40:52.472908Z  INFO garage_api::generic_server: Response: error 404 Not Found, Bucket not found: received

The issue is that received/ is being interpreted as a bucket name instead of a virtual directory as intended.
Also, if I use ':' instead of '/', with key 'received:user1:524bb5c8-c585-4123-b36a-1257d826325b:avatar.png', I got:

2024-02-29T11:46:35.611013Z  INFO garage_api::generic_server: [::ffff:192.168.215.0]:53469 HEAD /
2024-02-29T11:46:46.581825Z  INFO garage_api::generic_server: [::ffff:192.168.215.0]:53469 PUT /received%3Auser1%3A524bb5c8-c585-4123-b36a-1257d826325b%3Aavatar.png?x-id=PutObject
2024-02-29T11:46:46.582313Z  INFO garage_api::generic_server: Response: error 400 Bad Request, Bad request: Invalid create bucket XML query

Please, how would I fix that?

Thank you very much for garage! Previously, I was using minio with `aws-sdk-s3` in Rust. Now, I am attempting to transition to garage, but my previous code that was working no longer functions correctly. In this code snippet, I am trying to upload a file to an S3 bucket named `mustore-data` with the key `received/user1:886773de-cc58-4d2b-81bb-b4db05349817:avatar.png`: ```rust let _put_response = self .client .put_object() .bucket(&self.settings.bucket_name) .key(key.as_ref()) .content_encoding(mediatype.to_string()) .body( ByteStream::try_from(SdkBody::from(bytes)) .context("Failed to create ByteStream from bytes")?, ) .send() .await .context("Failed to upload file to the object storage")?; ``` However, the output I received indicates an error: ``` 2024-02-29T11:40:32.826738Z INFO garage_api::generic_server: [::ffff:192.168.215.0]:53406 HEAD / 2024-02-29T11:40:52.472320Z INFO garage_api::generic_server: [::ffff:192.168.215.0]:53406 PUT /received/user1%3A886773de-cc58-4d2b-81bb-b4db05349817%3Aavatar.png?x-id=PutObject 2024-02-29T11:40:52.472908Z INFO garage_api::generic_server: Response: error 404 Not Found, Bucket not found: received ``` The issue is that `received/` is being interpreted as a bucket name instead of a virtual directory as intended. Also, if I use ':' instead of '/', with key 'received:user1:524bb5c8-c585-4123-b36a-1257d826325b:avatar.png', I got: ``` 2024-02-29T11:46:35.611013Z INFO garage_api::generic_server: [::ffff:192.168.215.0]:53469 HEAD / 2024-02-29T11:46:46.581825Z INFO garage_api::generic_server: [::ffff:192.168.215.0]:53469 PUT /received%3Auser1%3A524bb5c8-c585-4123-b36a-1257d826325b%3Aavatar.png?x-id=PutObject 2024-02-29T11:46:46.582313Z INFO garage_api::generic_server: Response: error 400 Bad Request, Bad request: Invalid create bucket XML query ``` Please, how would I fix that?
Owner

There are two style of URLs in AWS S3: path-style and dns-style. Here, Garage is expecting a path-style URL, where the fist component is the name of the bucket, but your client is sending a dns-style request, where the bucket name is supposed to be part of the host name. Configure your client to use path style (the option is variously called use_path_style or force_path_style) and it should work.

There are two style of URLs in AWS S3: path-style and dns-style. Here, Garage is expecting a path-style URL, where the fist component is the name of the bucket, but your client is sending a dns-style request, where the bucket name is supposed to be part of the host name. Configure your client to use path style (the option is variously called use_path_style or force_path_style) and it should work.
Author

@lx, That works, thanks you very much!

@lx, That works, thanks you very much!
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Deuxfleurs/garage#738
No description provided.