duanhan8757 2016-11-01 20:05
浏览 1938
已采纳

通过POST请求上传大型base64图像时丢失信息

I am attempting to upload an image string(base64) and save it as an image server side.

The issue is that when I upload a large image(1200 px width jpg full quality) I lose some information as it's uploading.

My code works though because smaller images upload and save just fine.

I have already checked my ini php file and have max filesize upload and max post high enough that it really shouldn't be the issue (40 m).

My information gets passed along like this:

  • get base64 image data from phone camera (works, can display image client side)

  • place image data into a hidden form field (no information lost at this point)

  • send data through ajax POST request (no bugs or anything)

  • receive the image string from php POST variable (This is where I lose the information)

-- strlen before upload: 5,253,100

-- strlen after upload: 524,288

  • save image by using base64_decode (works fine, saves smaller images properly)

Now when I upload a larger image, I don't get any errors. The code still spits out a picture, but the picture is just the top quarter or so of the original image with the rest being grey.

I'd post some of my code but I'm fairly confident it isn't in my code since everything was working perfectly till I upped my image size. I am definitely losing the information at some point during the POST request.

Any tips to point me in the right direction would be lovely. Thanks for reading.

  • 写回答

1条回答 默认 最新

  • duannima8347 2016-11-04 17:46
    关注

    I've found the solution. It turns out that my data was getting cut off when I placed it inside a textbox. I didn't know textboxes had a maximum limit but in my case the textbox was truncating my data at 524288 characters.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥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,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵
  • ¥15 cfx离心泵非稳态计算