2017-05-19 6 views
0

私は角度jの初心者です。私は会社のために角度jを使用する既存のプロジェクトに取り組んでいます。私は角度jsを使用して私のwebapiプロジェクトのフォルダの中にある画像を取得する方法を知りたいです。 webapiはpostメソッドとして宣言されており、私はHTMLビューでユーザーのイメージを取得する必要があります。私はwebapiのロジックを作成したが、角度jsになると私は固執され、それを行う方法については全く考えていない。角度jsを使用してwebapi URLフォルダから画像を取得する方法は?

以下

は私のWeb API POSTメソッド

[AcceptVerbs("POST")] 
    [Route("profile/{userid}/")] 
    public byte[] GetScreenshot(string userid) 
    { 
     var imgPath = string.Format("{0}/{1}.png", Common.AppHelper.FolderPathProfilePicture, userid); 

     if (!File.Exists(imgPath)) 
     { 
       imgPath = string.Format("{0}/no.png", Common.AppHelper.FolderPathDeviceScreenshot); 
      if (!File.Exists(imgPath)) 
       imgPath = System.Web.Hosting.HostingEnvironment.MapPath("~/doc/thumbnail") + "\no.png"; 
      if (!File.Exists(imgPath)) 
       return null; 
     } 
     return File.ReadAllBytes(imgPath); 
    } 

である、これは私が私から画像を取得するための角度JSを使用する方法が分からない

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> 

    <span class="glyphicon glyphicon-pencil" style="margin-top: 7px;"></span> 
    <div class="pull-right" style="margin-top: 5px;"> 
     <span class="text-info" data-ng-bind-html="accountLoginName | to_trusted" style="font-size: 12px;"></span> 


<!-- image must show at this img src --> 

       <img src="" alt="" class="img-responsive img-circle" style="height: 25px; width: 25px; border-radius: 50% !important;" />&nbsp;<span class="caret"></span> 
       <ul class="dropdown-menu"> 


        <li><a ng-click="popupProfilePictureControl.showPopup(loginAccount)">Change profile picture</a></li> 
        <li><a href="#">Change corporation</a></li> 
        <li><a href="#">Change password</a></li> 
        <li class="divider"></li> 
        <li><a href="#">Help</a></li> 
        <li><a href="#">Support</a></li> 

        <li class="divider"></li> 
        <li><a href="#logout">Logout</a></li> 
       </ul> 




    </div> 
</div> 

私のhtmlページですwebapi。親切に私を導く。

+0

あなたはすることができます角度の変数に画像を取得しますか?たとえば、POSTを正常に呼び出すと、返されたバイトの処理方法がわかりません。またはPOSTを呼び出してイメージを取得するのに問題がありますか? – Aaron

+0

投稿を呼び出す際に問題が発生しています。私はどこにそれを呼ぶべきか分からない。 –

+2

サービス中。 *非常に*基本的な紹介のためのW3Schools:https://www.w3schools.com/angular/angular_services.asp ...そしてもっと現実の世界のために:http://stackoverflow.com/questions/29780147/how-to-返信画像from http-get-in-angularjs – Aaron

答えて

0

あなたはおそらく単なる文字列で戻り値を置き換える、画像のBase64文字列を使用することができますJSで

return Convert.ToBase64String(File.ReadAllBytes(imgPath)); 

ウェブAPI結果(この使用してjQueryの)後:

$(".img-responsive img-circle").attr("src",dataBase64Str); 
+0

彼の問題はWeb APIのPOSTを呼び出すことにあるようですが、HTMLに入るのではありません。彼はサービス$ httpコールを必要とします。 – Aaron

関連する問題