|
1 | 1 | # @vercel/blob |
2 | 2 |
|
| 3 | +## 2.0.0 |
| 4 | + |
| 5 | +### Major Changes |
| 6 | + |
| 7 | +- 0b8ead9: **BREAKING CHANGE:** |
| 8 | + |
| 9 | + To continue receiving `onUploadCompleted` callback once a file is uploaded with Client Uploads when **not hosted on Vercel**, you need to provide the `callbackUrl` at the `onBeforeGenerateToken` step when using `handleUpload`. |
| 10 | + |
| 11 | + **When hosted on Vercel:** |
| 12 | + No code changes required. The `callbackUrl` is inferred from [Vercel system environment variables](https://vercel.com/docs/environment-variables/system-environment-variables): |
| 13 | + |
| 14 | + - In preview environment: `VERCEL_BRANCH_URL` when available, otherwise `VERCEL_URL` |
| 15 | + - In production environment: `VERCEL_PROJECT_PRODUCTION_URL` |
| 16 | + |
| 17 | + If you're not hosted on Vercel or you're not using Vercel system environment variables, your will need to provide the `callbackUrl`: |
| 18 | + |
| 19 | + **Before:** |
| 20 | + |
| 21 | + ```ts |
| 22 | + await handleUpload({ |
| 23 | + body, |
| 24 | + request, |
| 25 | + onBeforeGenerateToken: async (pathname) => { |
| 26 | + /* options */ |
| 27 | + }, |
| 28 | + onUploadCompleted: async ({ blob, tokenPayload }) => { |
| 29 | + /* code */ |
| 30 | + }, |
| 31 | + }); |
| 32 | + ``` |
| 33 | + |
| 34 | + **After:** |
| 35 | + |
| 36 | + ```ts |
| 37 | + await handleUpload({ |
| 38 | + body, |
| 39 | + request, |
| 40 | + onBeforeGenerateToken: async (pathname) => { |
| 41 | + return { callbackUrl: 'https://example.com' }; // the path to call will be automatically computed |
| 42 | + }, |
| 43 | + onUploadCompleted: async ({ blob, tokenPayload }) => { |
| 44 | + /* code */ |
| 45 | + }, |
| 46 | + }); |
| 47 | + ``` |
| 48 | + |
| 49 | + **For local development:** |
| 50 | + Set the `VERCEL_BLOB_CALLBACK_URL` environment variable to your tunnel URL: |
| 51 | + |
| 52 | + ```bash |
| 53 | + VERCEL_BLOB_CALLBACK_URL=https://abc123.ngrok-free.app |
| 54 | + ``` |
| 55 | + |
| 56 | + See the updated documentation at https://vercel.com/docs/vercel-blob/client-upload to know more. |
| 57 | + |
| 58 | + **Details:** |
| 59 | + |
| 60 | + Before this commit, during Client Uploads, we would infer the `callbackUrl` at the client side level (browser) based on `location.href` (for convenience). |
| 61 | + This is wrong and allows browsers to redirect the onUploadCompleted callback to a different website. |
| 62 | + |
| 63 | + While not a security risk, because the blob urls are already public and the browser knows them, it still pose a risk of database drift if you're relying on onUploadCompleted callback to update any system on your side. |
| 64 | + |
3 | 65 | ## 1.1.1 |
4 | 66 |
|
5 | 67 | ### Patch Changes |
|
0 commit comments