Server assets using `getItemRaw` is inconsistent
Environment
Node 20+ Nitro 2.7.2
Reproduction
StackBlitz
npm run dev returns Buffer
npm run build && npm run preview returns string
Describe the bug
Getting the raw file using getItemRaw return Buffer vs string in preview.
Testet with node-server and firebase providers.
Additional context
I'm trying to get a static server assets PDF generation.
Example included as /pdf in the StackBlitz.
I know getItemRaw is still marked experimental, but I don't see any other API to access simple PNG data?
Logs
No response
Might be related for firebase - see e.g. https://github.com/unjs/nitro/issues/1903
I assume this issue is storage related and also seem to be the case for node-server.
The linked issue #1903 (im the author) was regarding receiving the raw body from requests.
https://github.com/unjs/nitro/discussions/2256
Hi,
in my case I was trying to use pdfmake in the vercel
I've been facing 2 issues
- when I use
getItemRawthe output is inconsistent as it's described above (locally works fine for images) - pdfmake doesn't accept neither buffer nor base64 for the fonts, it has to be path to regular file
in order to use file asset as a regular file I had to do a small hack to include assets into the final bundle.
in the package.json I had to update the build script like this
"build": "nitropack build && cp ./assets ./.vercel/output/functions/__nitro.func -r",
then I can use regular path, for example using path
const fontDescriptors = {
Roboto: {
normal: path.join('assets', 'fonts/Roboto-Regular.ttf'),
bold: path.join('assets', 'fonts/Roboto-Medium.ttf'),
italics: path.join('assets', 'fonts/Roboto-Italic.ttf'),
bolditalics: path.join('assets', 'fonts/Roboto-MediumItalic.ttf'),
},
}
@pi0 is there is any better option how to append a custom folder to final build ideally through the nitro config?
Thanks :)
Hi, I have the same problem with getItem
This api...
...returns a string in dev mode and raw in preview. This is not provider related.
I think it might be related with: #2481
Since getItemRaw is now marked as experimental, I've reverted to using getItem and created a new buffer from there.
This seems to be consistant both in dev, preview and node-server.
const rawBuffer = await storage.getItem('myCert.pem').then((item) => Buffer.from(item as any))
Feels a bit hacky and quite redundant, but I guess it will have to do for now. Maybe a getItemBuffer is needed?
Proposed storage.get("key", { type: "bytes" ) (https://github.com/unjs/unstorage/issues/528) will ensure return-type is consistent.
Current raw implementation between drivers currently varies and has different return values.
Amazing! Thanks for the heads up Pooya ♥️