无法使用角度 js 将 base 64 图像数据发送到服务器

Unable to send base 64 Image data to server with angular js

本文关键字:数据 图像 服务器 base js      更新时间:2023-09-26

我正在尝试使用$http Post请求将Base64图像数据发送到服务器,它适用于较低分辨率的图像(高达100KB),但不适用于更高分辨率的图像(尝试6MB文件)。

收到错误:400 错误请求。

    $http({url:ServerURL,method: "POST",
            params: {imageData:base64_imgData}
    }).then(function(response) {
      console.log(response.data);
      console.log(response.status);
    },function(response) {
       console.log(response.data);
       console.log(response.status);
    });

请帮助如何克服这个问题。

谢谢你的回答杰伊,你的回答帮助了我。

使用 Jquery Ajax 请求解决的问题

$.ajax({
   type: "POST",
   url: ServerURL,
   data: { 
         imageData:base64_imgData
   },
   cache: false,
   contentType: "application/x-www-form-urlencoded",
   success: function (result) {
       console.log("Success");
   }
});

我认为对于大尺寸图像,不建议将 base 64 图像数据发送到服务器,这是耗尽内存的好方法。 最好使用文件并发送文件。

如果您希望

使用基数 64 样式发送数据,请将 base 64 分成多个部分(在确定大小的标准之后,请自行决定数量部分)并对最初创建的对象进行更新。否则,请参考下面的一些角度模块进行文件上传:

http://ngmodules.org/modules/angular-file-upload

如果是 JAVA Rest API,我会立即推荐多部分表单数据文件上传机制。如果您想要更多,请告诉我。