Azure / Azure/static-web-apps

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

Abierto
#1,237 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Sin datos de lenguaje
Estrellas
346
Forks
67
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza con el binding de respuesta de function.json y el código de index.js que asigna context.res; después, reproduce la solicitud en Postman para comparar los headers devueltos y los bytes de la imagen. El trabajo estará terminado cuando se haya identificado por qué la SWA API cambia image/jpeg y se haya documentado o implementado una forma de devolver un JPEG legible con el Content-Type previsto.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
azure, node.js
Área
api, cloud
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.