-
Notifications
You must be signed in to change notification settings - Fork 70
[blob] implement client upload #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
correttojs
merged 20 commits into
main
from
fabiobenedetti/sto-635-allow-uploading-a-blob-4mb
Jun 15, 2023
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
06db622
implement client token
correttojs e71b55e
add tests
correttojs 062be07
isomorphic put
correttojs c2e4ece
update doc, support edge
correttojs 39577e1
review doc and uploadCompleted
correttojs c34f2aa
update upload-token interface
correttojs ae15343
implement verifyCallbackSignature
correttojs 44ce452
add maximumSizeInBytes and allowedContentTypes
correttojs 3937b59
Apply suggestions from code review
correttojs f4f89ff
Update packages/blob/README.md
correttojs 776bff1
rename routes
correttojs d0c37b8
Apply suggestions from code review
correttojs 8df83ea
Apply suggestions from code review
correttojs 52e2f45
add comment
correttojs b4ca2c6
add comment
correttojs a7698d5
fix prettier
correttojs 994711d
configure client tests
correttojs abc933c
fix readme
correttojs 6eafd26
fix browser test
correttojs cac3d94
add changeset
correttojs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 | ||
--- | ||
|
||
Implement Client Upload |
This file contains hidden or 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 hidden or 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,3 @@ | ||
const { TextEncoder, TextDecoder } = require('node:util'); | ||
|
||
Object.assign(global, { TextDecoder, TextEncoder }); |
This file contains hidden or 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 hidden or 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,7 @@ | ||
export function createHmac() { | ||
throw new Error('Not implemented'); | ||
} | ||
|
||
export function timingSafeEqual() { | ||
throw new Error('Not implemented'); | ||
} |
This file contains hidden or 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,60 @@ | ||
import { put } from './index'; | ||
|
||
jest.mock('undici', () => ({ | ||
fetch: (): unknown => | ||
Promise.resolve({ | ||
status: 200, | ||
json: () => | ||
Promise.resolve({ | ||
url: `${BASE_URL}/storeid/foo-id.txt`, | ||
size: 12345, | ||
uploadedAt: '2023-05-04T15:12:07.818Z', | ||
pathname: 'foo.txt', | ||
contentType: 'text/plain', | ||
contentDisposition: 'attachment; filename="foo.txt"', | ||
}), | ||
}), | ||
})); | ||
const BASE_URL = 'https://blob.vercel-storage.com'; | ||
|
||
describe('blob client', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('put', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should upload a file from the client', async () => { | ||
await expect( | ||
put('foo.txt', 'Test Body', { | ||
access: 'public', | ||
token: 'vercel_blob_client_123_token', | ||
}), | ||
).resolves.toMatchInlineSnapshot(` | ||
{ | ||
"contentDisposition": "attachment; filename="foo.txt"", | ||
"contentType": "text/plain", | ||
"pathname": "foo.txt", | ||
"size": 12345, | ||
"uploadedAt": 2023-05-04T15:12:07.818Z, | ||
"url": "https://blob.vercel-storage.com/storeid/foo-id.txt", | ||
} | ||
`); | ||
}); | ||
|
||
it('should throw when calling `put()` with a server token', async () => { | ||
await expect( | ||
put('foo.txt', 'Test Body', { | ||
access: 'public', | ||
contentType: 'text/plain', | ||
token: 'vercel_blob_rw_123_TEST_TOKEN', | ||
}), | ||
).rejects.toThrow( | ||
new Error('Vercel Blob: client upload only supports client tokens'), | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.