调用 api 将图像上传到服务器时如何修复错误 414 uri 太长 for mobilefirst 8

How to fix error 414 uri too long when calling api for upload image to server for mobilefirst 8

我将应用程序从 mfp 7.1 更新到 8。对于 mfp 7,上传图像的功能工作正常但对于 mfp 8 尝试调用相同的方法服务器也抛出 uri long.The 服务器没有任何更改,仅限应用程序端

但是如果我发送的照片没有 base64,api return success.The 相机功能的源代码对于 mfp7.1 和 8[=12 版本完全相同=]

mfp7.1 server request(Working)

var locale  =   localStorageService.get('locale');
var rptList =   localStorageService.get('rptList');
var channel =   localStorageService.get('rptChannel');
var os      =   localStorageService.get('rptOs');
var type    =   localStorageService.get('rptOption');
var station =    
localStorageService.get('mrReportHistoryDetailStation');
var desc    =    
localStorageService.get('mrReportHistoryDetailDesc');
var loc     =   localStorageService.get('rptLoc');
var accNo   =   localStorageService.get('rptAccNo');
var issueType   =   localStorageService.get('rptIssueType');
var photo   =   localStorageService.get('rptPhoto');    

console.log(rptList);
console.log('Make Report adapter');
var deferred = $q.defer();
var invocationData = {
    adapter : "Report",
    procedure : "makeReport",
    parameters : [{
      LOCALE:locale,
      CHANNEL:channel,
      CLIENT_OS:os,
      TYPE:type,
      ISSUE_TYPE:issueType,
      STATION:(type === 'GENERAL_INQUIRY')?"" : station,
      CATEGORY:(type === 'GENERAL_INQUIRY')?station : "",
      DESCRIPTION:desc,
      LOCATION:loc,
      CONTRACT_ACC_NO:accNo,
      PHOTOS:photo
    }]
};
console.log(JSON.stringify(invocationData));
var options = {
    onSuccess : $.proxy(function (result){
      deferred.resolve(result.invocationResult);
    }, this),
    onFailure : $.proxy(function (res){
      deferred.reject(res);
    }, this)
};



 mfp8 (Not Working)


 var locale = localStorageService.get('locale');
  var rptList = localStorageService.get('rptList');
  var channel = localStorageService.get('rptChannel');
  var os = localStorageService.get('rptOs');
  var type = localStorageService.get('rptOption');
  var station = 
  localStorageService.get('mrReportHistoryDetailStation');
  var desc = localStorageService.get('mrReportHistoryDetailDesc');
  var loc = localStorageService.get('rptLoc');
  var accNo = localStorageService.get('rptAccNo');
  var issueType = localStorageService.get('rptIssueType');
  var photo = localStorageService.get('rptPhoto');


  console.log(rptList);
  console.log('Make Report adapter');
  var deferred = $q.defer();
  var invocationData = {
    LOCALE: locale,
    CHANNEL: channel,
    CLIENT_OS: os,
    TYPE: type,
    ISSUE_TYPE: issueType,
    STATION: type === 'GENERAL_INQUIRY' ? '' : station,
    CATEGORY: type === 'GENERAL_INQUIRY' ? station : '',
    DESCRIPTION: desc,
    LOCATION: loc,
    CONTRACT_ACC_NO: accNo,
    PHOTOS: photo
  };

  var resourceRequest = new WLResourceRequest(
    '/adapters/Report/makeReport',
    WLResourceRequest.POST
  );
  alert('resource');
  console.log(resourceRequest);
  resourceRequest.setQueryParameter('params', [invocationData]);
  resourceRequest.send().then(
    response => {
      alert('return');
      this.content = response.responseJSON;
      console.log(
        'Report make report====>>>' + JSON.stringify(this.content)
      );
      deferred.resolve(this.content);
      alert('Success');
    },
    function(error) {
      console.log('error message' + JSON.stringify(error));
      deferred.reject(error);
    }
  );

它 return mfp7.1 代码成功,但对于 mfp 8 它 return 错误 414 uri 太长。但如果没有照片 api return 成功。 照片是base64Image

尝试使用 FormParams 而不是 QueryParams,因为 QueryParams 将在 URL 中传递,并且它对字符数有一些限制。相反,您可以将 json 作为 FormParam,

var request = WLResourceRequest(url, method, options);
request.sendFormParameters(json).then(
    function(response) {
        // success flow
    },
    function(error) {
        // fail flow
    }
);

如需进一步参考,请访问下方 link 并查看 WLResourceRequest 的方法。

http://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/api/client-side-api/javascript/client/