Skip to content

Commit

Permalink
Fix R2 create bucket endpoint (#1653)
Browse files Browse the repository at this point in the history
* Fix R2 create bucket endpoint

* changeset

* Styling

* Fix test
  • Loading branch information
WalshyDev authored Aug 22, 2022
1 parent 61e3f00 commit 46b73b5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-peaches-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Fixed R2 create bucket API endpoint. The `wrangler r2 bucket create` command should work again
7 changes: 4 additions & 3 deletions packages/wrangler/src/__tests__/r2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ describe("wrangler", () => {
function mockCreateRequest(expectedBucketName: string) {
const requests = { count: 0 };
setMockResponse(
"/accounts/:accountId/r2/buckets/:bucketName",
"PUT",
([_url, accountId, bucketName]) => {
"/accounts/:accountId/r2/buckets",
"POST",
([_url, accountId], { body }) => {
expect(accountId).toEqual("some-account-id");
const bucketName = JSON.parse(body as string).name;
expect(bucketName).toEqual(expectedBucketName);
requests.count += 1;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/wrangler/src/r2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export async function createR2Bucket(
accountId: string,
bucketName: string
): Promise<void> {
return await fetchResult<void>(
`/accounts/${accountId}/r2/buckets/${bucketName}`,
{ method: "PUT" }
);
return await fetchResult<void>(`/accounts/${accountId}/r2/buckets`, {
method: "POST",
body: JSON.stringify({ name: bucketName }),
});
}

/**
Expand Down

0 comments on commit 46b73b5

Please sign in to comment.