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 网络科学导论,网络控制
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)