繁体   English   中英

将json中图像的base64字节数组传递给webApi

[英]Passing base64 byte array of image in json to webApi

我已将通过jQuery上传的图像转换为base64字节数组/字符串。

借助代码:

function readImage(input) {
        debugger;
        if (input.files && input.files[0]) {
            var FR = new FileReader();
            var a = null;
            FR.onload = function (e) {
                array = e.target.result;
            };
            FR.readAsDataURL(input.files[0]);
   }

我现在将数组通过json传递到我的Web Api并遇到问题。

我的json呼叫就像:

 $.getJSON('api/TestImage' + '/' + JSON.stringify(array))
            .done(function (data) {
                //doSomething
            });

我的动作是:

       public IHttpActionResult TestImage(String id) 
        {
            return Ok(id);
        }

因此,任何人都可以说出问题所在以及需要做什么。

提前致谢..

为什么要使用URL和GET发送图像? 您应该使用请求正文中的POST发送该消息。 base64中的图像可能很大,您可能会遇到url的一些限制。 这个

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM