我有一个非常长的字符数的base64图像,当我尝试通过Fetch POST API发送它时,它被切断并使我的PHP文件服务器端无法接受图像。 base64是我下面代码中的b64data变量。任何解决方案或想法将不胜感激!
function submitPhoto(){
fetch('http://fanbeauties.com/app/submit-photo.php?pass=MY_PASS', {
method: "POST",
headers: {
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
},
body: 'name='+name+'&email='+email+'&market='+market+'&picture='+b64data
});
};
PHP:
<?php
$title = $_POST['name'];
$market = $_POST['market'];
$account = "414890";
$date = date("Y-m-d");
$pass = $_GET['pass'];
$image = $_POST['picture'];
$title = $_POST['name'];
//$source_type = "app";
if($pass == "Fan412") {
//Clean base64 String
//$image = str_replace(' ', '', $image);
//Convert base64 into image
$filename_path = md5(time().uniqid()).".jpg";
$decoded=base64_decode($image);
file_put_contents("../MY_FOLDER/".$filename_path,$decoded);
// Insert Info into Database
$mysqli->query("INSERT INTO MY_TABLE (account, date, title, market, image) VALUES ('$account', '$date', '$title', '$market', '$filename_path')");
// close connection
$mysqli->close();
} else {
die();
} ?>
答案 0 :(得分:-1)
然后将base64_code切成碎片怎么样 在提交整个表格之前张贴他们......
POSTDATA
{
'code':one piece_code,
'current_position':1,
'full_pieces_count':你裁员的计数
}
在php中你可以用redis来缓存带有sorted_set piece1 piece2的base64_pieces ...(得分使用你发布的current_position) 最终作品上传成功后...... 将它们组合成pic以保存然后给js一个img_url 然后提交整个表格
btw:设置最大长度以发布所有字符串...如果它太长了...将其剪切并发布为async / sync