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 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建