|
1 | 1 | # @vercel/blob |
2 | 2 |
|
| 3 | +## 2.0.1 |
| 4 | + |
| 5 | +### Patch Changes |
| 6 | + |
| 7 | +- e2de71a: Upgrade undici to fix security issue warning |
| 8 | + |
3 | 9 | ## 2.0.0 |
4 | 10 |
|
5 | 11 | ### Major Changes |
|
38 | 44 | body, |
39 | 45 | request, |
40 | 46 | onBeforeGenerateToken: async (pathname) => { |
41 | | - return { callbackUrl: 'https://example.com' }; // the path to call will be automatically computed |
| 47 | + return { callbackUrl: "https://example.com" }; // the path to call will be automatically computed |
42 | 48 | }, |
43 | 49 | onUploadCompleted: async ({ blob, tokenPayload }) => { |
44 | 50 | /* code */ |
|
102 | 108 | - Overwriting blobs now requires to use `allowOverwrite: true`. Example: |
103 | 109 |
|
104 | 110 | ```js |
105 | | - await put('file.png', file, { access: 'public' }); |
| 111 | + await put("file.png", file, { access: "public" }); |
106 | 112 |
|
107 | | - await put('file.png', file, { access: 'public' }); // This will throw |
| 113 | + await put("file.png", file, { access: "public" }); // This will throw |
108 | 114 |
|
109 | | - put('file.png', file, { access: 'public', allowOverwrite: true }); // This will work |
| 115 | + put("file.png", file, { access: "public", allowOverwrite: true }); // This will work |
110 | 116 | ``` |
111 | 117 |
|
112 | 118 | How to upgrade: |
|
240 | 246 | const abortController = new AbortController(); |
241 | 247 |
|
242 | 248 | vercelBlob |
243 | | - .put('canceled.txt', 'test', { |
244 | | - access: 'public', |
| 249 | + .put("canceled.txt", "test", { |
| 250 | + access: "public", |
245 | 251 | abortSignal: abortController.signal, |
246 | 252 | }) |
247 | 253 | .then((blob) => { |
248 | | - console.log('Blob created:', blob); |
| 254 | + console.log("Blob created:", blob); |
249 | 255 | }); |
250 | 256 |
|
251 | 257 | setTimeout(function () { |
|
296 | 302 |
|
297 | 303 | ```ts |
298 | 304 | const { key, uploadId } = await vercelBlob.createMultipartUpload( |
299 | | - 'big-file.txt', |
300 | | - { access: 'public' }, |
| 305 | + "big-file.txt", |
| 306 | + { access: "public" } |
301 | 307 | ); |
302 | 308 |
|
303 | | - const part1 = await vercelBlob.uploadPart(fullPath, 'first part', { |
304 | | - access: 'public', |
| 309 | + const part1 = await vercelBlob.uploadPart(fullPath, "first part", { |
| 310 | + access: "public", |
305 | 311 | key, |
306 | 312 | uploadId, |
307 | 313 | partNumber: 1, |
308 | 314 | }); |
309 | 315 |
|
310 | | - const part2 = await vercelBlob.uploadPart(fullPath, 'second part', { |
311 | | - access: 'public', |
| 316 | + const part2 = await vercelBlob.uploadPart(fullPath, "second part", { |
| 317 | + access: "public", |
312 | 318 | key, |
313 | 319 | uploadId, |
314 | 320 | partNumber: 2, |
|
318 | 324 | fullPath, |
319 | 325 | [part1, part2], |
320 | 326 | { |
321 | | - access: 'public', |
| 327 | + access: "public", |
322 | 328 | key, |
323 | 329 | uploadId, |
324 | | - }, |
| 330 | + } |
325 | 331 | ); |
326 | 332 | ``` |
327 | 333 |
|
|
330 | 336 | For multipart methods, since some of the data remains consistent (uploadId, key), you can make use of the `createMultipartUploader`. This function stores certain data internally, making it possible to offer convinient `put` and `complete` functions. |
331 | 337 |
|
332 | 338 | ```ts |
333 | | - const uploader = await vercelBlob.createMultipartUploader('big-file.txt', { |
334 | | - access: 'public', |
| 339 | + const uploader = await vercelBlob.createMultipartUploader("big-file.txt", { |
| 340 | + access: "public", |
335 | 341 | }); |
336 | 342 |
|
337 | 343 | const part1 = await uploader.uploadPart(1, createReadStream(fullPath)); |
|
397 | 403 | Usage: |
398 | 404 |
|
399 | 405 | ```ts |
400 | | - const blob = await put('file.png', file, { |
401 | | - access: 'public', |
| 406 | + const blob = await put("file.png", file, { |
| 407 | + access: "public", |
402 | 408 | multipart: true, // `false` by default |
403 | 409 | }); |
404 | 410 |
|
405 | 411 | // and: |
406 | | - const blob = await upload('file.png', file, { |
407 | | - access: 'public', |
408 | | - handleUploadUrl: '/api/upload', |
| 412 | + const blob = await upload("file.png", file, { |
| 413 | + access: "public", |
| 414 | + handleUploadUrl: "/api/upload", |
409 | 415 | multipart: true, |
410 | 416 | }); |
411 | 417 | ``` |
|
415 | 421 | More examples: |
416 | 422 |
|
417 | 423 | ```ts |
418 | | - import { createReadStream } from 'node:fs'; |
| 424 | + import { createReadStream } from "node:fs"; |
419 | 425 |
|
420 | 426 | const blob = await vercelBlob.put( |
421 | | - 'elon.mp4', |
| 427 | + "elon.mp4", |
422 | 428 | // this works 👍, it will gradually read the file from the system and upload it |
423 | | - createReadStream('/users/Elon/me.mp4'), |
424 | | - { access: 'public', multipart: true }, |
| 429 | + createReadStream("/users/Elon/me.mp4"), |
| 430 | + { access: "public", multipart: true } |
425 | 431 | ); |
426 | 432 | ``` |
427 | 433 |
|
428 | 434 | ```ts |
429 | 435 | const response = await fetch( |
430 | | - 'https://example-files.online-convert.com/video/mp4/example_big.mp4', |
| 436 | + "https://example-files.online-convert.com/video/mp4/example_big.mp4" |
431 | 437 | ); |
432 | 438 |
|
433 | 439 | const blob = await vercelBlob.put( |
434 | | - 'example_big.mp4', |
| 440 | + "example_big.mp4", |
435 | 441 | // this works too 👍, it will gradually read the file from internet and upload it |
436 | 442 | response.body, |
437 | | - { access: 'public', multipart: true }, |
| 443 | + { access: "public", multipart: true } |
438 | 444 | ); |
439 | 445 | ``` |
440 | 446 |
|
|
446 | 452 | Now the the SDK validates if the operation is a folder creation by checking if the pathname ends with a trailling slash. |
447 | 453 |
|
448 | 454 | ```ts |
449 | | - const blob = await vercelBlob.put('folder/', { |
450 | | - access: 'public', |
| 455 | + const blob = await vercelBlob.put("folder/", { |
| 456 | + access: "public", |
451 | 457 | addRandomSuffix: false, |
452 | 458 | }); |
453 | 459 | ``` |
|
552 | 558 | upload, |
553 | 559 | handleUpload, |
554 | 560 | generateClientTokenFromReadWriteToken, |
555 | | - } from '@vercel/blob/client'; |
| 561 | + } from "@vercel/blob/client"; |
556 | 562 | ``` |
557 | 563 |
|
558 | 564 | Here are the new features: |
|
0 commit comments