2016-11-22 3 views
2

イメージをbase64に変換してSharepointサイトにアップロードしようとしていますが、これは400を投げています。私が正しくチェックしたとき、私が送信しているbase64がjavascriptでエンドコードされていることが判明しました。これはsharepointで予想されるものとは異なります。違いを説明する2つの画像を添付しました。誰も私はJavaScriptを使用して適切なエンコードされたデータを取得するのを助けることができますか?JavaScriptとC#(フロントエンドとバックエンド)のbase64にイメージが異なる

javascript encoded base64

c# encoded base64

var files = $("#myfile").get(0).files; 

     var reader = new FileReader(); 
     reader.readAsDataURL(files[0]); 

     reader.onload = function() { 
      console.log(reader.result); 
     } 
+0

参照:http://stackoverflow.com/questions/21325661/convert-image-path-to-base64-string – Dil85

答えて

0

試みることができる:reader.result.split("base64,")[1]

は、文字列の"base64,"開始を削除します。

0
Please try this , i am using this in my project , its working for me 



    if (file.ContentType.Contains("image")) 
       { 
        string theFileName = Path.GetFileName(file.FileName); 
        byte[] thePictureAsBytes = new byte[file.ContentLength]; 
        using (BinaryReader theReader = new BinaryReader(file.InputStream)) 
        { 
         thePictureAsBytes = theReader.ReadBytes(file.ContentLength); 
        } 
        string thePictureDataAsString = Convert.ToBase64String(thePictureAsBytes); 

       } 


    "thePictureDataAsString " variable got Base64 string 


......................................................................... 


i am getting file like this in my project 

public ActionResult SaveMake(string inputMakeName, HttpPostedFileBase file) 
     { 
      MakeModel objMakeModel = new MakeModel(); 
      if (file.ContentType.Contains("image")) 
      { 
       string theFileName = Path.GetFileName(file.FileName); 
       byte[] thePictureAsBytes = new byte[file.ContentLength]; 
       using (BinaryReader theReader = new BinaryReader(file.InputStream)) 
       { 
        thePictureAsBytes = theReader.ReadBytes(file.ContentLength); 
       } 
       string thePictureDataAsString = Convert.ToBase64String(thePictureAsBytes); 
       objMakeModel.ImageBase64 = thePictureDataAsString; 
       objMakeModel.Make1 = inputMakeName; 
      } 

      string response = _apiHelper.ConvertIntoReturnStringPostRequest<MakeModel>(objMakeModel, "api/Transaction/SaveMakes/"); 
      // string response = _apiHelper.SaveMake(objMakeModel, "api/Transaction/SaveMakes/"); 
      return RedirectToAction("AddVehicleMaintenance"); 
     } 
関連する問題