C#Web API - 上传大图像时内存不足

时间:2018-01-05 06:40:48

标签: c# json base64

使用JAP字符串上传包含base64的大图像时,我在C#中遇到问题

代码JS:

function uploadImagePlace() {
    return new Promise((resolve, reject) => {
        var photo = $('#thumbnail-preview').attr('src');
        var isPhotoDB = $('#thumbnail-preview').attr('data-photodb');
        if (photo && isPhotoDB == 'false') {
            var formData = new FormData();
            formData.append("Photo", ($('#thumbnail-preview').attr('src') == '') ? "" : $('#thumbnail-preview').attr('src'));
            $.ajax({
                url: serverFile + "UploadImagePlace/AddImage",
                type: 'POST',
                data: formData,
                processData: false,
                contentType: false,
                success: function (result) {
                    resolve({ error: false, data: result });
                },
                error: function () {
                    reject({ error: true, data: 'Error upload' });
                }
            });
        } else {
            resolve({ error: false, data: null });
        }
    });
}

代码C#

var httpRequest = HttpContext.Current.Request;
var ListPhoto = httpRequest["Photo"].ToString();
var lstPlaceImg = JsonConvert.DeserializeObject<List<PhotoUploadViewModel>>(ListPhoto);

catch异常错误:

  

类型&#39; system.outofmemoryexception&#39;被扔了。   Ex.Source:Newtonsoft.Json

我不知道如何解决这个问题。任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

尝试将这些行添加到配置标记内的Config文件中。

config.supportedHandleTypes = NSSet setWithObjects:[NSNumber numberWithInteger:CXHandleTypePhoneNumber], nil];

它对我有用! 感谢。