Skip to content
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

[blob] implement client upload #179

Merged
merged 20 commits into from
Jun 15, 2023

Conversation

correttojs
Copy link
Collaborator

@correttojs correttojs commented Jun 6, 2023

implement client upload

  • implement generateClientTokenFromReadWriteToken
  • add client upload test page for serverless and edge

@changeset-bot
Copy link

changeset-bot bot commented Jun 6, 2023

🦋 Changeset detected

Latest commit: cac3d94

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@vercel/blob Minor
vercel-storage-integration-test-suite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jun 6, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
vercel-storage-next-integration-test-suite ✅ Ready (Inspect) Visit Preview Jun 15, 2023 10:57am

packages/blob/client/package.json Outdated Show resolved Hide resolved
packages/blob/package.json Outdated Show resolved Hide resolved
@vvo
Copy link
Member

vvo commented Jun 7, 2023

Once ready, let's ship this as experimental/next tag on npm so we can give a try to the published built package to ensure endpoints and types are correctly working.

@vvo
Copy link
Member

vvo commented Jun 9, 2023

@correttojs Should we allow providing custom metadata at token creation time? When using S3-presigned URLs you can add metadata. Here's why I think we should think about a way to do so: As a customer using this feature for avatar uploads (example), when onUploadCompletedCallbackUrl triggers, then it will contain the url of the avatar.

Now as a customer, I'd like to store this url in my database to update the avatar of the right user. To do so I can either:

  • parse the url if it contains the user id (perhaps it doesn't)
  • or use metadata from the onUploadCompletedCallbackUrl (= the metadata needs to be set at token creation time).

I propose we allow this:

generateUploadTokenFromReadWriteToken({
  pathname: 'foo.txt',
  onUploadCompletedUrl: 'https://example.com/',
  metadata: 'userId=314' // any string is ok, this can be used by customers and it would contain comma separated values, json, whatever we don't care
  token: 'TEST_TOKEN',
});

Thoughts?

packages/blob/package.json Outdated Show resolved Hide resolved
@vvo
Copy link
Member

vvo commented Jun 9, 2023

Once we make this right, let's make sure we update the README with an example that uses this feature. With a similar code than the current README example.

packages/blob/src/client.ts Outdated Show resolved Hide resolved
packages/blob/src/index.test.ts Outdated Show resolved Hide resolved
@correttojs
Copy link
Collaborator Author

@correttojs Should we allow providing custom metadata at token creation time? When using S3-presigned URLs you can add metadata. Here's why I think we should think about a way to do so: As a customer using this feature for avatar uploads (example), when onUploadCompletedCallbackUrl triggers, then it will contain the url of the avatar.

Now as a customer, I'd like to store this url in my database to update the avatar of the right user. To do so I can either:

  • parse the url if it contains the user id (perhaps it doesn't)
  • or use metadata from the onUploadCompletedCallbackUrl (= the metadata needs to be set at token creation time).

I propose we allow this:

generateUploadTokenFromReadWriteToken({
  pathname: 'foo.txt',
  onUploadCompletedUrl: 'https://example.com/',
  metadata: 'userId=314' // any string is ok, this can be used by customers and it would contain comma separated values, json, whatever we don't care
  token: 'TEST_TOKEN',
});

Thoughts?

@vvo added onUploadCompletedCallbackUrlArgs, feel free to suggest a better name

Copy link
Member

@vvo vvo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No major review changes, this looks beautiful and will be a tremendous addition to Vercel Blob. Congrats!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants