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

Images are incorrectly encoded after Azure Functions Deployment #100

Closed
danielroe opened this issue Apr 12, 2022 · 4 comments · Fixed by #2079
Closed

Images are incorrectly encoded after Azure Functions Deployment #100

danielroe opened this issue Apr 12, 2022 · 4 comments · Fixed by #2079
Assignees
Labels
bug Something isn't working preset:azure

Comments

@danielroe
Copy link
Member

danielroe commented Apr 12, 2022

When deploying a Nitro app with the azure-functions preset, static Images such as .pngs and .jpgs are rendered incorrectly. (They are converted to string, which messes with their encoding.)

Issues to check:

context: nuxt/nuxt#12677

@mcremer-able
Copy link
Contributor

Got this ever resolved, because I have the same issues with fonts aswell.
In the generated function code we have

async function handle(context, req) {
  const url = "/" + (req.params.url || "");
  const { body, status, statusText, headers } = await nitroApp.localCall({
    url,
    headers: req.headers,
    method: req.method,
    body: req.rawBody
  });
  context.res = {
    status,
    headers,
    body: body ? body.toString() : statusText
  };
}

for static assets we use readFile wich returns a buffer, but the buffer.toString method sometime returns larger Object wich causes issues.

promises.readFile("./font.woff").then((e) => {
  const ogLen = e.length;
  const stringLen = e.toString().length;
  console.log({ ogLen, stringLen });
});
// { ogLen: 561776, stringLen: 532428 }

If I change it to body: body ? body : statusText, it seems to work.
Would a pr with that change resolve this ?

@markgibbons25
Copy link

markgibbons25 commented Dec 7, 2022

@danielroe hey mate any update on this one?
I don't mind testing the above suggestion out on https://github.com/unjs/nitro/blob/main/src/runtime/entries/azure-functions.ts but I'm not sure how to incorporate that change into my nuxt project.

@edwh
Copy link

edwh commented Feb 2, 2023

@markgibbons25 I tried this using patch-package and @mcremer-able's suggestion, which does the trick for me.

The patch file is at https://github.com/Freegle/iznik-nuxt3/blob/master/patches/nitropack%2B2.1.0.patch

This issue was a godsend, as I was struggling to track down the problem, but loading an SVG successfully confirmed it was this one.

@planty
Copy link

planty commented Apr 11, 2023

i'm also experiencing this problem with the favicon and images deployed to azure functions. the fix @mcremer-able describes fixes the issue in my case too.
is there any update on when this might be fixed? or i can raise a pr if you like?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working preset:azure
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants