You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using the upload method from @vercel/blob/client in a sveltekit app (w svelte5) and I am missing the possibility to add an authorization header on the request sent from client to my api. I need the authorization header in the server code below marked with "// HERE"
(I adopted the sample code from the next.js example in the documentation)
import{error,json}from"@sveltejs/kit";import{handleUpload,typeHandleUploadBody}from"@vercel/blob/client";exportasyncfunctionPOST({ request }){constbody=(awaitrequest.json())asHandleUploadBody;// EITHER HEREtry{constjsonResponse=awaithandleUpload({
body,
request,onBeforeGenerateToken: async(pathname/* clientPayload */)=>{// Generate a client token for the browser to upload the file// ⚠️ Authenticate and authorize users before generating the token.// Otherwise, you're allowing anonymous uploads.// OR HEREreturn{allowedContentTypes: ["image/jpeg","image/png","image/gif"],tokenPayload: JSON.stringify({// optional, sent to your server on upload completion// you could pass a user id from auth, or a value from clientPayload})};},onUploadCompleted: async({ blob, tokenPayload })=>{// Get notified of client upload completion// ⚠️ This will not work on `localhost` websites,// Use ngrok or similar to get the full upload flowconsole.log("blob upload completed",blob,tokenPayload);try{// Run any logic after the file upload completed// const { userId } = JSON.parse(tokenPayload);// await db.update({ avatar: blob.url, userId });}catch(error){thrownewError("Could not update user");}}});returnjson(jsonResponse);}catch(err){// The webhook will retry 5 times waiting for a 200returnerror(400,(errasError).message);}}
The text was updated successfully, but these errors were encountered:
Hey @luismeyer,
indeed, you're right. I've seen this ticket before, but didn't look into the code deep enough. I think, if custom headers are forwarded from upload to retrieveClientToken the same way as requested by #420, it is exactly the same issue :) Closing in favor of #420.
I am using the upload method from @vercel/blob/client in a sveltekit app (w svelte5) and I am missing the possibility to add an authorization header on the request sent from client to my api. I need the authorization header in the server code below marked with "// HERE"
(I adopted the sample code from the next.js example in the documentation)
Client
Server (src\routes\api\files\upload+server.ts)
The text was updated successfully, but these errors were encountered: