2017-08-07 10 views
0

を返します。テスト時に私のIDが返されるのを見ることができませんでした。代わりに、私はブラウザで返された画像しか見ることができません。クロムでHTTPGETは私は以下の機能が画像とIDを返すために使用されて持っている画像及びId

  int id = 0; 
      using (Bitmap bitmap = Image.Generate(context, out id)) 
      { 
       HttpResponse response = context.Response; 
       response.CacheControl = "no-cache"; 
       response.ContentType = "image/JPG"; 
       bitmap.Save(response.OutputStream, ImageFormat.Jpeg); 
       response.End(); 

       var responseModel = new ResponseModel 
       { 
        Id = id, 
        Image = bitmap 
       }; 

       return Ok(responseModel); 
      }; 

応答プレビュー: enter image description here

画像が含まれている場合、これは、応答を返すための適切な方法は何ですか?もしそうなら、イメージとIDを含むajax呼び出しからこの応答データを取得するにはどうすればよいですか(Json.parseで行うことができますか?これはbytedataですか?)あなたができる

答えて

1

ことの一つは、この答え

Asp.net Web API return File with metadata about the file

ように私は、モバイル上でHttpResponseMessageのヘッダ内のIDを追加していているので、私は後で私の答えを更新しますが、基本的に、あなただけのイメージがあることだろうメッセージ本文とヘッダー内のメタデータ次にクライアントは応答ヘッダーを解析して、必要なものを取得します。私はこれを過去に使ってきました。約束通り

サンプル

public HttpResponseMessage Get() 
{ 
    XDocument xDoc = GetXMLDocument(); 
    int id = CallToGetMyId(); 

    var response = this.Request.CreateResponse(
     HttpStatusCode.OK, 
     xDoc.ToString(), 
     this.Configuration.Formatters.XmlFormatter 
    ); 
    response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") 
    { 
     FileName = "image.png" 
    }; 
    response.Headers.Add("Id", id); 
    return response; 
} 
関連する問題