douchuose2514 2016-04-19 22:03
浏览 177
已采纳

通过表单传递base64编码图像

I am using an image editing tool for users to upload their images and adjust: http://foliotek.github.io/Croppie/

I am able to shorten the base64 string by sending it through a couple functions. I am then trying to insert this into a hidden field and submit the form.

$('#submit-update-business').on('click', function(e){
    e.preventDefault();
    // console.log(vanilla.get());
    vanilla.result('canvas', 'viewport', 'png', 0).then(function(src){
        var processed = Base64.encode(JSON.stringify(src));
        $('#new_image').val(processed);
        $('#update-business').submit();
    });
});

I know the string is long, but I can't figure out any other way to do this. I've also seen answers that suggest submitting the form through ajax, but this seems to have the same pitfalls. This actually manages to work ok on desktop browsers. It's the mobile ones that have a problem. I can limit the dimensions of the image to less than 3000x3000, but unfortunately phones seem to be taking much higher quality photos.

The tool I'm using, Croppie, has a way to get the data points and zoom, but not the orientation. If there is a way to save this data, or use the base64 data, and re-render the image, and somehow use that image so the image actually goes through, that would be great. If there is a solution I can use just for mobile, that would work too, since it works just fine on desktop.

  • 写回答

1条回答 默认 最新

  • dpcwz210393 2016-04-20 10:28
    关注

    With ajax post instead of submit you don't need a hidden_field if it has length limits in mobile browser. Base64 encoding overhead is not necessary too if you don't need it on a server side.

    .post(
      "/ajaxpostURL.php",
      {
        new_image: processed, // or new_image: src,
        other_form_param_or_data: 'some_data'
      }
    );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题