Aws-lambda-dotnet: ブループリントASP.NETCoreWebアプリで動作するバイナリサポートの取得

作成日 2018年03月08日  ·  5コメント  ·  ソース: aws/aws-lambda-dotnet

ASP.NET Core2統合でバイナリサポートを機能させるのに問題があります。

そこで、「ASP.NET Core Web App」ブループリントを試してみましたが、実際にはfavicon.icoファイルが含まれており、公開時に表示されません。

ブループリントは、自分のマシンで実行するのと同じように、箱から出してすぐに機能するはずだと思います。 または、favicon.icoを削除する必要があるかもしれません。

バイナリレスポンスコンテンツに関する手順をここで読みました: https

そこで、 LambdaEntryPoint.Init()次の行を追加しました: RegisterResponseContentEncodingForContentType("image/x-icon", ResponseContentEncoding.Base64);

そして、コンソールにバイナリメディアタイプを追加しました。
image

Lambdaログは、応答がbase64でエンコードされていることを正しく示しています。

START RequestId: 11a7e691-22d3-11e8-9b13-ef274abd9c03 Version: $LATEST
Incoming GET requests to /favicon.ico
ASP.NET Core Request PathBase: /Prod, Path: /favicon.ico
[Information] Microsoft.AspNetCore.Hosting.Internal.WebHost: Request starting GET https://XXX.execute-api.eu-west-1.amazonaws.com/Prod/favicon.ico 
[Information] Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware: Sending file. Request path: '/favicon.ico'. Physical path: '/var/task/wwwroot/favicon.ico' 
[Information] Microsoft.AspNetCore.Hosting.Internal.WebHost: Request finished in 0.5675ms 200 image/x-icon 
Response Base 64 Encoded: True
END RequestId: 11a7e691-22d3-11e8-9b13-ef274abd9c03

APIゲートウェイログ:

Starting execution for request: 577e5bb3-22d4-11e8-b061-1775958b34a4
HTTP Method: GET, Resource Path: /favicon.ico
Successfully completed execution
Method completed with status: 200

私はどの部分が欠けていますか?

ラムダプロキシ統合でバイナリを機能させていない人の投稿がかなりたくさん見つかりました。 ですから、一般的な問題があるのではないかと思います。

guidance

最も参考になるコメント

私はこれをここに残すつもりなので、うまくいけば他の誰かを1時間節約できます...

デフォルトでは、.pngファイルのリクエストのヘッダーには、「画像/ PNG形式」ではない「画像/ PNG形式」である「同意します」! 追加すると、すべてが機能しました。

        protected override void Init(IWebHostBuilder builder)
        {
            //NB: Serverless WebAPI needs to have special config to serve binary file types: 
            RegisterResponseContentEncodingForContentType("image/png", ResponseContentEncoding.Base64);
            RegisterResponseContentEncodingForContentType("image/jpeg", ResponseContentEncoding.Base64);
            RegisterResponseContentEncodingForContentType("image/gif", ResponseContentEncoding.Base64);
            RegisterResponseContentEncodingForContentType("image/apng", ResponseContentEncoding.Base64);
            RegisterResponseContentEncodingForContentType("image/webp", ResponseContentEncoding.Base64);
            RegisterResponseContentEncodingForContentType("image/x-icon", ResponseContentEncoding.Base64);

            builder
                .UseStartup<Startup>();
        }

編集:ChromeとIE11のAcceptヘッダーはデフォルトとしてimage/apngを使用しているようですが、Firefoxは<img>タグに対して*/*を送信します! あなたは追加することができます*/*上記のリストに、それは仕事が、YMMVに_seems_。

全てのコメント5件

AWSサポートと話しているときにこの問題を解決しました。

ソリューション:
「バイナリメディアタイプ」を変更した後、「APIのデプロイ」に移動してクリックする必要があります。

image

こんにちは、私はあなたの手順に従いましたが、それでも画像/アイコンを取得できませんでした。

あなたはあなたが言ったこと以上のことをしましたか?

ありがとう!

ええ、実際には、ブラウザに画像を表示しようとするときは、BinaryMediaTypesを*/*に設定する必要があります。

BinaryMediaType image/x-iconは、クライアントがAcceptヘッダーを送信した場合にのみ機能します。 テストする方法は次のとおりです。

$ curl -sH "Accept: image/x-icon" https://XXX.execute-api.eu-west-1.amazonaws.com/Prod/favicon.ico -o /tmp/favicon.ico
$ file /tmp/favicon.ico
/tmp/favicon.ico: MS Windows icon resource - 3 icons, 16x16, 256-colors

それを無視します :)

私はこれをここに残すつもりなので、うまくいけば他の誰かを1時間節約できます...

デフォルトでは、.pngファイルのリクエストのヘッダーには、「画像/ PNG形式」ではない「画像/ PNG形式」である「同意します」! 追加すると、すべてが機能しました。

        protected override void Init(IWebHostBuilder builder)
        {
            //NB: Serverless WebAPI needs to have special config to serve binary file types: 
            RegisterResponseContentEncodingForContentType("image/png", ResponseContentEncoding.Base64);
            RegisterResponseContentEncodingForContentType("image/jpeg", ResponseContentEncoding.Base64);
            RegisterResponseContentEncodingForContentType("image/gif", ResponseContentEncoding.Base64);
            RegisterResponseContentEncodingForContentType("image/apng", ResponseContentEncoding.Base64);
            RegisterResponseContentEncodingForContentType("image/webp", ResponseContentEncoding.Base64);
            RegisterResponseContentEncodingForContentType("image/x-icon", ResponseContentEncoding.Base64);

            builder
                .UseStartup<Startup>();
        }

編集:ChromeとIE11のAcceptヘッダーはデフォルトとしてimage/apngを使用しているようですが、Firefoxは<img>タグに対して*/*を送信します! あなたは追加することができます*/*上記のリストに、それは仕事が、YMMVに_seems_。

このページは役に立ちましたか?
0 / 5 - 0 評価