Skip to content

Commit

Permalink
feat(blob): Ensure contentType always has a value in blob results (#803)
Browse files Browse the repository at this point in the history
* feat(blob): Ensure contentType always has a value in blob results

Before this commit, when using extension less pathnames or unknown extensions
(like wxss) then:
- Errors would be imprecise ("contentType  is not allowed", empty string issue)
- When creating blobs, contentType would be undefined

Once you upgrade:
- We will default to 'application/octet-stream' when we can't find a correct
  mime type from extension or no extension in pathname
- Errors will be precise ("contentType 'application/octet-stream' is not
  allowed)
- contentType is always present on put/upload/copy

This is a BREAKING CHANGE if you were used to do something like:
```js
if (contentType === undefined) {
  // do something
}
```

* changeset

* fix tests
  • Loading branch information
vvo authored Dec 4, 2024
1 parent 3491560 commit 7872e61
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/rich-ligers-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vercel/blob': minor
---

contentType default is now 'application/octet-stream' instead of `undefined`
2 changes: 1 addition & 1 deletion packages/blob/src/api.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('api', () => {
authorization: 'Bearer 123',
'x-api-blob-request-attempt': '0',
'x-api-blob-request-id': expect.any(String) as string,
'x-api-version': '7',
'x-api-version': '8',
},
method: 'POST',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/blob/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export interface BlobApiError {
// This version is used to ensure that the client and server are compatible
// The server (Vercel Blob API) uses this information to change its behavior like the
// response format
const BLOB_API_VERSION = 7;
const BLOB_API_VERSION = 8;

function getApiVersion(): string {
let versionOverride = null;
Expand Down
18 changes: 9 additions & 9 deletions packages/blob/src/client.browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('client', () => {
authorization: 'Bearer vercel_blob_client_fake_123',
'x-api-blob-request-attempt': '0',
'x-api-blob-request-id': `fake:${Date.now()}:${requestId}`,
'x-api-version': '7',
'x-api-version': '8',
},
method: 'PUT',
},
Expand Down Expand Up @@ -207,7 +207,7 @@ describe('client', () => {
authorization: 'Bearer vercel_blob_client_fake_token_for_test',
'x-api-blob-request-attempt': '0',
'x-api-blob-request-id': `fake:${Date.now()}:${requestId}`,
'x-api-version': '7',
'x-api-version': '8',
'x-mpu-action': 'create',
},
method: 'POST',
Expand All @@ -224,7 +224,7 @@ describe('client', () => {
authorization: 'Bearer vercel_blob_client_fake_token_for_test',
'x-api-blob-request-attempt': '0',
'x-api-blob-request-id': `fake:${Date.now()}:${requestId}`,
'x-api-version': '7',
'x-api-version': '8',
'x-mpu-action': 'upload',
'x-mpu-key': 'key',
'x-mpu-upload-id': 'uploadId',
Expand All @@ -243,7 +243,7 @@ describe('client', () => {
authorization: 'Bearer vercel_blob_client_fake_token_for_test',
'x-api-blob-request-attempt': '0',
'x-api-blob-request-id': `fake:${Date.now()}:${requestId}`,
'x-api-version': '7',
'x-api-version': '8',
'x-mpu-action': 'upload',
'x-mpu-key': 'key',
'x-mpu-upload-id': 'uploadId',
Expand All @@ -266,7 +266,7 @@ describe('client', () => {
authorization: 'Bearer vercel_blob_client_fake_token_for_test',
'x-api-blob-request-attempt': '0',
'x-api-blob-request-id': `fake:${Date.now()}:${requestId}`,
'x-api-version': '7',
'x-api-version': '8',
'x-mpu-action': 'complete',
'x-mpu-key': 'key',
'x-mpu-upload-id': 'uploadId',
Expand Down Expand Up @@ -349,7 +349,7 @@ describe('client', () => {
authorization: 'Bearer vercel_blob_client_fake_token_for_test',
'x-api-blob-request-attempt': '0',
'x-api-blob-request-id': `fake:${Date.now()}:${requestId}`,
'x-api-version': '7',
'x-api-version': '8',
'x-mpu-action': 'create',
},
method: 'POST',
Expand All @@ -366,7 +366,7 @@ describe('client', () => {
authorization: 'Bearer vercel_blob_client_fake_token_for_test',
'x-api-blob-request-attempt': '0',
'x-api-blob-request-id': `fake:${Date.now()}:${requestId}`,
'x-api-version': '7',
'x-api-version': '8',
'x-mpu-action': 'upload',
'x-mpu-key': 'key',
'x-mpu-upload-id': 'uploadId',
Expand All @@ -385,7 +385,7 @@ describe('client', () => {
authorization: 'Bearer vercel_blob_client_fake_token_for_test',
'x-api-blob-request-attempt': '0',
'x-api-blob-request-id': `fake:${Date.now()}:${requestId}`,
'x-api-version': '7',
'x-api-version': '8',
'x-mpu-action': 'upload',
'x-mpu-key': 'key',
'x-mpu-upload-id': 'uploadId',
Expand All @@ -408,7 +408,7 @@ describe('client', () => {
authorization: 'Bearer vercel_blob_client_fake_token_for_test',
'x-api-blob-request-attempt': '0',
'x-api-blob-request-id': `fake:${Date.now()}:${requestId}`,
'x-api-version': '7',
'x-api-version': '8',
'x-mpu-action': 'complete',
'x-mpu-key': 'key',
'x-mpu-upload-id': 'uploadId',
Expand Down
2 changes: 1 addition & 1 deletion packages/blob/src/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface CopyBlobResult {
url: string;
downloadUrl: string;
pathname: string;
contentType?: string;
contentType: string;
contentDisposition: string;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/blob/src/put-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface PutBlobResult {
url: string;
downloadUrl: string;
pathname: string;
contentType?: string;
contentType: string;
contentDisposition: string;
}

Expand Down

0 comments on commit 7872e61

Please sign in to comment.