C# Webservice PHP不';无法接收base64大图像
我有一个无法解释的问题 我有一个C#程序,它可以将图像(截图,某个url的整个网页)编码发送到base64C# Webservice PHP不';无法接收base64大图像,c#,php,base64,C#,Php,Base64,我有一个无法解释的问题 我有一个C#程序,它可以将图像(截图,某个url的整个网页)编码发送到base64 static string ImageToBase64(System.Drawing.Image image, System.Drawing.Imaging.ImageFormat format) { using (MemoryStream ms = new MemoryStream()) { // Convert I
static string ImageToBase64(System.Drawing.Image image, System.Drawing.Imaging.ImageFormat format)
{
using (MemoryStream ms = new MemoryStream())
{
// Convert Image to byte[]
image.Save(ms, format);
byte[] imageBytes = ms.ToArray();
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
return base64String;
}
}
// image is typeof Bitmap
string myImageData = ImageToBase64(image, System.Drawing.Imaging.ImageFormat.Jpeg);
using (WebClient client = new WebClient())
{
try
{
byte[] response = client.UploadValues("http://production/ws/imageBuilder", new NameValueCollection()
{
{ "myImageData", HttpUtility.UrlEncode(this.myImageData) }
{ "Url_", url.Authority },
{ "token", ImageHash }
});
Debug.WriteLine("Server Said: " + System.Text.Encoding.Default.GetString(response));
byte[] response2 = client.UploadValues("http://localhost/ws/imageBuilder", new NameValueCollection()
{
{ "myImageData", HttpUtility.UrlEncode(this.myImageData) }
{ "Url_", url.Authority },
{ "token", ImageHash }
});
Debug.WriteLine("Server Said: " + System.Text.Encoding.Default.GetString(response2));
}
catch(Exception e) {Debug.WriteLine(e.Message);}
}
在PHP方面,我只做了一些测试
echo "length before decode ".strlen($_POST['myImageData']);
$imageData = base64_decode(urldecode($_POST['myImageData']));
echo "length after decode ".strlen($imageData);
返回的图像较大(例如1280 x 10000)
因此,在我的本地WAMP服务器(在Windows 7上)上,我收到了映像,但在生产(在Linux上)上,我什么也没有收到
但是使用“小”图像作为示例维度“1280 x 1024”没关系,我的变量$\u POST['myImageData']
在生产中不是空的,它工作正常
[4908] Server Said: length before decode 66292 length after decode 46210
[4908] Server Said: length before decode 66292 length after decode 46210
更新:图像是小JPG(介于200ko和1.5mo之间)
在我的php.in产品中,我有
upload_max_filesize = 20M
post_max_size = 18M
我生产中的Apache是mod_proxy如果我不得不大胆猜测,我会说检查php.ini中的“post_max_size”参数。它在linux服务器上的设置可能低于WAMP服务器。您是否达到了上载限制?如果您将图像作为
多部分/表单数据发送
,您的运气可能会更好。然后,Web服务器将给您一条错误消息作为文件输入,而不是文件输入。另一件需要注意的事情是,base64编码使您的数据膨胀了约33%。我的post_max_大小足够了。这只是一个JPEG图像,介于200ko和1.5 mo之间:/I将尝试多部分/表单数据。我的post_max_大小足够了。它只是一个JPEG图像,大约1mo:/
upload_max_filesize = 20M
post_max_size = 18M