-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(blob): add createFolder method (#751)
* feat(blob): add createFolder method And remove variadic calls from main put methods, which will allow us to more easily upgrade to newer TS versions. Related: - #682 - #667 * changeset * update desc * update test * update
- Loading branch information
Showing
8 changed files
with
66 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@vercel/blob': minor | ||
--- | ||
|
||
Add createFolder method. Warning, if you were using the standard put() method to created fodlers, this will now fail and you must move to createFolder() instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { requestApi } from './api'; | ||
import type { BlobCommandOptions } from './helpers'; | ||
import { putOptionHeaderMap, type PutBlobApiResponse } from './put-helpers'; | ||
|
||
export interface CreateFolderResult { | ||
pathname: string; | ||
url: string; | ||
} | ||
|
||
/** | ||
* Creates a folder in your store. Vercel Blob has no real concept of folders, our file browser on Vercel.com displays folders based on the presence of trailing slashes in the pathname. Unless you are building a file browser system, you probably don't need to use this method. | ||
* | ||
* Use the resulting `url` to delete the folder, just like you would delete a blob. | ||
* @param pathname - Can be user1/ or user1/avatars/ | ||
* @param options - Additional options like `token` | ||
*/ | ||
export async function createFolder( | ||
pathname: string, | ||
options: BlobCommandOptions = {}, | ||
): Promise<CreateFolderResult> { | ||
const path = pathname.endsWith('/') ? pathname : `${pathname}/`; | ||
|
||
const headers: Record<string, string> = {}; | ||
|
||
headers[putOptionHeaderMap.addRandomSuffix] = '0'; | ||
|
||
const response = await requestApi<PutBlobApiResponse>( | ||
`/${path}`, | ||
{ | ||
method: 'PUT', | ||
headers, | ||
signal: options.abortSignal, | ||
}, | ||
options, | ||
); | ||
|
||
return { | ||
url: response.url, | ||
pathname: response.pathname, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters