Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 3523

Issue when Uploading PDF files from UI5

$
0
0

Hi Experts,


We have an issue with uploading .PDF attachments via angularjs

Upload works via REST client (postman) as binary data. But not in angularjs.

Angularjs results in a malformed file.


The file is read via file reader (readAsBinaryString).


Code goes like this:


$scope.upload = function($files) {

    if ($files) {

      var r = new FileReader();

      r.onloadend = function(e) {  //end

        var vdata = e.target.result;

        $files[0].binarydata = window.btoa(vdata); //new Uint8Array(r.result);//strTohex(vdata);

        var url = sapUrl+"ZCSMOB_ATTACHMENT_GEN_GW_SRV/FILE_ATTACHMENTSSet";

        $http({method: 'GET', url: url, headers: {'X-CSRF-Token': 'Fetch'}}).then(function(d){

          var token = d.headers('X-CSRF-TOKEN');

          $http({method: 'POST', url: url, headers: {'X-CSRF-Token': token, 'Content-Type': 'application/pdf', 'slug': 'IvBusType~BUS2080#IvFileDesc~Test#IvFileName~Test.PDF#IvIsPicture~X#IvObjKey~002300000281#IvFileType~PDF'}, 'data': $files[0].binarydata}).then(  // , transformRequest: []

            function(d) {

              console.log(d);

            }, function (e) {

              console.log(e);

              //console.log(e.data.error.message.value);

            });

        });

      }

      r.readAsBinaryString($files[0]);

      //r.readAsArrayBuffer($files[0]);

    }

  }

 

Your Help is very much appreciated.


Thanks.


Viewing all articles
Browse latest Browse all 3523

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>