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
Basically, I want to serve assets from a event handler in server.
Questions:
Is it worth adding caching for static assets?
If yes, I am facing below issue.
When cached handler is called for first time, it returns asset directly and works fine. (Image in my case). Now, after caching, I believe that image is in the form of buffer and thus, gets stringified which is causing the issue. The handler than return stringified version of Buffer.
exportdefaultdefineEventHandler(async(event)=>{// THIS WORKS!constkey=getRouterParam(event,"key");constasset=awaitblobStorage.getItemRaw(key);returnasset;});exportdefaultdefineCachedEventHandler(async(event)=>{// THIS DOESN'Tconstkey=getRouterParam(event,"key");constasset=awaitblobStorage.getItemRaw(key);returnasset;},{maxAge: 60*60,getKey(event){returngetRouterParam(event,"key")||"";},})
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Basically, I want to serve assets from a event handler in server.
Questions:
When cached handler is called for first time, it returns asset directly and works fine. (Image in my case). Now, after caching, I believe that image is in the form of buffer and thus, gets stringified which is causing the issue. The handler than return stringified version of
Buffer
.For full context, see: https://github.com/profilecity/vidur/blob/main/src/server/routes/assets/%5Bkey%5D.ts
Beta Was this translation helpful? Give feedback.
All reactions