laravelamazon-s3backblaze

How do I resolve this Backblaze B2 S3 Compatible API error?


I'm getting this error:

Unable to write file at location: profile-photos/rFfDwnJUhtTlcy87bDur4Co7q6UnDYEGRbdl6Bi0.jpg. Error executing "PutObject" on "https://xxx.s3.us-west-004.backblazeb2.com/profile-photos/rFfDwnJUhtTlcy87bDur4Co7q6UnDYEGRbdl6Bi0.jpg"; 
AWS HTTP error: Client error: `PUT https://xxx.s3.us-west-004.backblazeb2.com/profile-photos/rFfDwnJUhtTlcy87bDur4Co7q6UnDYEGRbdl6Bi0.jpg` resulted in a `400 Bad Request` response: 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<Error> 
  <Code>InvalidRequest</Code> 
  <Message>The request (truncated...) 
InvalidRequest (client): The request body was too small - 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<Error> 
  <Code>InvalidRequest</Code> 
  <Message>The request body was too small</Message> 
</Error>

when I use this code

Storage::disk('s3')->put('profile-photos', $photo);

to upload a file to Backblaze. What could I be doing wrong and how can I resolve this?

UPDATE After following the suggestion in the comment, I got this error:

Unable to write file at location: profile-photos/0Oafj0VpwBbrMtvgLEnBmGl3UsL4rrUaD7HLzRDA.jpg. Error executing "PutObject" on "https://xxx.s3.us-west-004.backblazeb2.com/profile-photos/0Oafj0VpwBbrMtvgLEnBmGl3UsL4rrUaD7HLzRDA.jpg"; AWS HTTP error: Client error: `PUT https://xxx.s3.us-west-004.backblazeb2.com/profile-photos/0Oafj0VpwBbrMtvgLEnBmGl3UsL4rrUaD7HLzRDA.jpg` resulted in a `400 Bad Request` response: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Error> <Code>InvalidArgument</Code> <Message>Unsupporte (truncated...) InvalidArgument (client): Unsupported value for canned acl 'private' - <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Error> <Code>InvalidArgument</Code> <Message>Unsupported value for canned acl 'private'</Message> </Error>

But despite the error, file upload was successful.


Solution

  • That's an odd one - B2 is saying that the request body - the photo's data - is smaller than the content length sent in the HTTP header.

    It's a long shot, but the only other occurrence of this error that I've seen suggests recreating the bucket and the app key.

    One possible root cause: B2 app keys can contain non-alphanumeric characters, while S3 secret keys never do. If your app key contains a / or a + then it's possible that this is causing Laravel to send incorrect data.