-
Notifications
You must be signed in to change notification settings - Fork 62
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 multipart option (#517)
It turns out, uploading large files using Vercel Blob has been a struggle for users. Before this change, file uploads were limited to around 200MB for technical reasons. Before this change, even uploading a file of 100MB could fail for various reasons (network being one of them). To solve this for good, we're introducting a new option to `put` and `upload` calls: `multipart: true`. This new option will make sure your file is uploaded parts by parts to Vercel Blob, and when some parts are failing, we will retry them. This option is available for server and client uploads. Usage: ```ts const blob = await put('file.png', file, { access: 'public', multipart: true // `false` by default }); // and: const blob = await upload('file.png', file, { access: 'public', handleUploadUrl: '/api/upload', multipart: true }); ``` If your `file` is a Node.js stream or a [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) then we will gradually read and upload it without blowing out your server or browser memory. More examples: ```ts import { createReadStream } from 'node:fs'; const blob = await vercelBlob.put( 'elon.mp4', // this works 👍, it will gradually read the file from the system and upload it createReadStream('/users/Elon/me.mp4'), { access: 'public', multipart: true } ); ``` ```ts const response = await fetch( 'https://example-files.online-convert.com/video/mp4/example_big.mp4', ); const blob = await vercelBlob.put( 'example_big.mp4', // this works too 👍, it will gradually read the file from internet and upload it response.body, { access: 'public', multipart: true }, ); ```
- Loading branch information
Showing
36 changed files
with
914 additions
and
73 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,55 @@ | ||
--- | ||
"@vercel/blob": minor | ||
"vercel-storage-integration-test-suite": patch | ||
--- | ||
|
||
feat(blob): Add multipart option to reliably upload medium and large files | ||
|
||
It turns out, uploading large files using Vercel Blob has been a struggle for users. | ||
Before this change, file uploads were limited to around 200MB for technical reasons. | ||
Before this change, even uploading a file of 100MB could fail for various reasons (network being one of them). | ||
|
||
To solve this for good, we're introducting a new option to `put` and `upload` calls: `multipart: true`. This new option will make sure your file is uploaded parts by parts to Vercel Blob, and when some parts are failing, we will retry them. This option is available for server and client uploads. | ||
|
||
Usage: | ||
```ts | ||
const blob = await put('file.png', file, { | ||
access: 'public', | ||
multipart: true // `false` by default | ||
}); | ||
|
||
// and: | ||
const blob = await upload('file.png', file, { | ||
access: 'public', | ||
handleUploadUrl: '/api/upload', | ||
multipart: true | ||
}); | ||
``` | ||
|
||
If your `file` is a Node.js stream or a [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) then we will gradually read and upload it without blowing out your server or browser memory. | ||
|
||
More examples: | ||
|
||
```ts | ||
import { createReadStream } from 'node:fs'; | ||
|
||
const blob = await vercelBlob.put( | ||
'elon.mp4', | ||
// this works 👍, it will gradually read the file from the system and upload it | ||
createReadStream('/users/Elon/me.mp4'), | ||
{ access: 'public', multipart: true } | ||
); | ||
``` | ||
|
||
```ts | ||
const response = await fetch( | ||
'https://example-files.online-convert.com/video/mp4/example_big.mp4', | ||
); | ||
|
||
const blob = await vercelBlob.put( | ||
'example_big.mp4', | ||
// this works too 👍, it will gradually read the file from internet and upload it | ||
response.body, | ||
{ access: 'public', multipart: true }, | ||
); | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
let debugIsActive = false; | ||
|
||
// wrapping this code in a try/catch in case some env doesn't support process.env (vite by default) | ||
try { | ||
if ( | ||
process.env.DEBUG?.includes('blob') || | ||
process.env.NEXT_PUBLIC_DEBUG?.includes('blob') | ||
) { | ||
debugIsActive = true; | ||
} | ||
} catch (error) { | ||
// noop | ||
} | ||
|
||
// Set process.env.DEBUG = 'blob' to enable debug logging | ||
export function debug(message: string, ...args: unknown[]): void { | ||
if (debugIsActive) { | ||
// eslint-disable-next-line no-console -- Ok for debugging | ||
console.debug(`vercel-blob: ${message}`, ...args); | ||
} | ||
} |
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
Oops, something went wrong.
898c14a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
vercel-storage-next-integration-test-suite – ./
vercel-storage-next-integration-test-suite-curated-tests.vercel.app
storage-rho.vercel.app
vercel-storage-next-integration-test-s-git-14bcac-curated-tests.vercel.app