Azure / Azure/static-web-apps

The API middleware obstructs image downloads, by altering Content-Type

Offen
#1,237 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Keine Sprachdaten
Sterne
346
Forks
67
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

- I have an SWA API endpoint running in node where I am trying to serve a jpg image to the browser.
- The image is fetched by index.js from an external endpoint that needs authentication.
- The image stream is delivered perfectly to index.js with the correct headers. I wait until the stream ends, but I can't figure out how to pipe the byte array through the SWA API middleware with the correct headers.
- As far as I can see the SWA API middleware is altering the defined Content-Type for no apparent reason?

My function.json looks like this:

{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"route": "image/{id}/{type}",
"methods": [
"get"
]
},
{
"type": "http",
"direction": "out",
"name": "res",
"dataType": "binary"
}
]
}

In index.js I set the headers like this:

context.res = {
body: buffer,
headers: {
"Content-Type": "image/jpeg"
}
}

But when I call the endpoint (from postman) I can see the Content-Type header value is overwritten:

**_image/jpeg; charset=utf-8_**

and the image file is unreadable for the client.

- Calling the external endpoint directly from postman works like a charm!
- What is the reason for this strange behaviour?
- How to mitigate it so we can serve an image from the SWA API?

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Beginne mit dem Response-Binding in function.json und dem index.js-Code, der context.res zuweist, und führe dann die Anfrage in Postman erneut aus, um die zurückgegebenen Header und Image-Bytes zu vergleichen. Abgeschlossen ist die Aufgabe, wenn identifiziert wurde, warum die SWA API image/jpeg ändert, und eine Möglichkeit dokumentiert oder implementiert wurde, ein lesbares JPEG mit dem vorgesehenen Content-Type zurückzugeben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
azure, node.js
Bereich
api, cloud
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.