【问题标题】:ASP.NET Deployment issue saving image to databaseASP.NET 部署问题将图像保存到数据库
【发布时间】:2018-12-29 20:44:43
【问题描述】:

当我将代码从 VS2015 部署到 IIS 时,我遇到了一个不寻常的问题。在 VS 中,当我运行 web 代码时,无论是调试还是发布,我选择并加载然后转换为 base64 的图像都会转换为字节数组并保存到数据库中,没有任何问题。但是,当我部署到 Web 服务器时,代码无法工作并且图像永远不会更新。我没有收到任何错误信息。只要我从VS运行它就可以了。 IIS 服务器上有什么需要配置的吗?任何帮助或 cmets 将不胜感激。

HTML 代码

<form class="input-group" id="img2b64">
<input id="inputFileToLoad" name="files" type="file" 
onchange="encodeImageFileAsURL();" />
</form>
<!-- is used to display b64 code and hold the b64 for ajax call to controller -->
<textarea id="b64" class="form-control"></textarea>

查询代码

 function encodeImageFileAsURL(cb) {
        return function () {
            var file = this.files[0];
            var reader = new FileReader();
            reader.onloadend = function () {
                cb(reader.result);
            }
            reader.readAsDataURL(file);
        }
    }

    $('#inputFileToLoad').change(encodeImageFileAsURL(function (base64Img) {
        $('#act_Photo').attr('src', base64Img);
        $('#b64').val(base64Img);
    }));

在控制器代码中

// model.ImageFile is the base64 string
if (!string.IsNullOrEmpty(model.ImageFile))
{
     // strip out base64 header
     int pos = model.ImageFile.LastIndexOf(',') + 1;
     string data = model.ImageFile.Substring(pos);
     // get byte array of base64 image
     byte[] bytes = Convert.FromBase64String(data);
     // convert and save as byte array to DB
     var acctImg = new WebImage(bytes).Resize(220, 200, false, true);
     // aRec.Photo is in DB record
     aRec.Photo = acctImg.GetBytes();
}

【问题讨论】:

    标签: asp.net image iis base64


    【解决方案1】:

    似乎一切都很好。我在 IIS 中重新启动了该站点。似乎是一个导致所有悲伤的缓存问题。有时我只是讨厌缓存。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-10
      相关资源
      最近更新 更多