Azure / Azure/static-web-apps

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

Aperta
#1,237 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Nessun dato sulla lingua
Stelle
346
Fork
67
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

- 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?

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia dal response binding di function.json e dal codice index.js che assegna context.res, quindi riproduci la richiesta in Postman per confrontare gli header restituiti e i byte dell'immagine. Il lavoro è completato quando è stato identificato il motivo per cui la SWA API modifica image/jpeg e documentato o implementato un modo per restituire un JPEG leggibile con il Content-Type previsto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
azure, node.js
Ambito
api, cloud
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.