vercel / storage

Vercel Postgres, KV, Blob, and Edge Config
https://vercel.com/storage
Apache License 2.0
517 stars 57 forks source link

@vercel/blob - Make onUploadCompleted optional #721

Open joaopedrocn opened 4 months ago

joaopedrocn commented 4 months ago

According to the documentation, the responsibility of the client upload route is to:

  1. Generate tokens for client uploads
  2. Listen for completed client uploads, so you can update your database with the URL of the uploaded file for example

I want to handle the database update with a server action though, so I just need the first part. However, typescript complains if I don't provide an onUploadCompleted callback. My suggestion is to make this callback optional, and do not send webhooks in that case.

vvo commented 4 months ago

@joaopedrocn thanks for opening this.

I want to handle the database update with a server action though

Can you provide us with more details as to what/how you're trying to accomplish? So we get a better understanding about why you do not need the onUploadCompleted. Thanks!

joaopedrocn commented 4 months ago

Hey, thanks for the reply.

So in my application there is a form where users (nutritionists) can upload supporting materials for their patients. This form has many inputs besides the file one (name, description, etc.). When the user selects a file through the file input, I want to upload this file to Vercel Blob right away, and only when the user submits the form with all required fields, persist everything in the database with a server action.

So in this case the onUploadCompleted is useless, because I don't want to do anything after the file is uploaded (I just need the blob url).

Shopify does something similar. In the create/edit a product page you can upload images, which will be stored right away, even if you don't end up creating/saving the product.