Azure / Azure/static-web-apps

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

オープン
#1,237 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
言語のデータがありません
スター
346
フォーク
67
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

function.json の response binding と context.res を設定する index.js コードから始め、次に Postman でリクエストを再現して、返されるヘッダーと画像バイトを比較します。SWA API が image/jpeg を変更する理由を特定し、意図した Content-Type で読み取り可能な JPEG を返す方法を文書化または実装できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
azure, node.js
領域
api, cloud
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。