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 tried ngrok but it was super laggy and is added complexity for my team.
I think in dev, blob uploadStart should automatically handle calling the api endpoint again on completion or provide some documentation to do so.
E.g.
// client sideexportconstuseVercelBlob: UseVercelBlob=()=>{constuserId=useUserId();returnasync(file,data,onComplete)=>{constclientPayload=Schema.encodeSync(Schema.parseJson(VercelBlobClientToken),)(data);constresponse=awaitupload(file.name,file,{
clientPayload,access: "public",handleUploadUrl: "/api/vercel-blob",});if(env.NEXT_PUBLIC_VERCEL_ENV==="development"){// must be a string so it gets double stringifiedconsttokenPayload: string=Schema.encodeSync(Schema.parseJson(VercelBlobPayloadToken),)({body: data.body,
userId,});// fake the api request that the webhook should have sentconstbody={type: "blob.upload-completed",payload: {
tokenPayload,blob: response,},};awaitfetch("/api/vercel-blob",{method: "POST",body: JSON.stringify(body),headers: {"Content-Type": "application/json",},});}onComplete(response);};};
// in api endpointconstbody=(awaitrequest.json())asHandleUploadBody;constsignature=env.VERCEL_ENV==="development"&&body.type==="blob.upload-completed"
? awaitsignPayload(JSON.stringify(body),// biome-ignore lint/style/noNonNullAssertion: <explanation>process.env.BLOB_READ_WRITE_TOKEN!,)
: null;//...handleUpload({//...// pass in the faked signaturerequest:
env.VERCEL_ENV==="development"
? ({headers: {"x-vercel-signature": signature,},}asunknownasIncomingMessage)
: request,})// helper functions taken from blob sourcecodefunctionimportKey(token: string): Promise<webcrypto.CryptoKey>{returnglobalThis.crypto.subtle.importKey("raw",newTextEncoder().encode(token),{name: "HMAC",hash: "SHA-256"},false,["sign","verify"],);}asyncfunctionsignPayload(payload: string,token: string,): Promise<string|undefined>{constsignature=awaitglobalThis.crypto.subtle.sign("HMAC",awaitimportKey(token),newTextEncoder().encode(payload),);returnBuffer.from(newUint8Array(signature)).toString("hex");}
Thoughts?
The text was updated successfully, but these errors were encountered:
I tried ngrok but it was super laggy and is added complexity for my team.
I think in dev, blob uploadStart should automatically handle calling the api endpoint again on completion or provide some documentation to do so.
E.g.
Thoughts?
The text was updated successfully, but these errors were encountered: