Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server assets using getItemRaw is inconsistent #1926

Closed
okydk opened this issue Nov 19, 2023 · 8 comments
Closed

Server assets using getItemRaw is inconsistent #1926

okydk opened this issue Nov 19, 2023 · 8 comments

Comments

@okydk
Copy link
Contributor

okydk commented Nov 19, 2023

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

@TheAlexLichter
Copy link
Member

Might be related for firebase - see e.g. #1903

@okydk
Copy link
Contributor Author

okydk commented Nov 19, 2023

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.

Copy link
Contributor

#2256

@kleinpetr
Copy link
Contributor

Hi,

in my case I was trying to use pdfmake in the vercel

I've been facing 2 issues

  1. when I use getItemRaw the output is inconsistent as it's described above (locally works fine for images)
  2. 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 :)

amandesai01 added a commit to profilecity/vidur that referenced this issue Aug 10, 2024
@Zebnastien
Copy link

Zebnastien commented Aug 15, 2024

Hi, I have the same problem with getItem

This api...
image
...returns a string in dev mode and raw in preview. This is not provider related.

I think it might be related with: #2481

@okydk
Copy link
Contributor Author

okydk commented Sep 19, 2024

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?

@pi0
Copy link
Member

pi0 commented Jan 7, 2025

Proposed storage.get("key", { type: "bytes" ) (unjs/unstorage#528) will ensure return-type is consistent.

Current raw implementation between drivers currently varies and has different return values.

@pi0 pi0 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 7, 2025
@okydk
Copy link
Contributor Author

okydk commented Jan 7, 2025

Amazing! Thanks for the heads up Pooya ♥️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants