1-得到base64编码图像URI
String imageData= canvas2.toDataUrl();
2-通过RPC调用向发送的图像数据服务器端
jdbc.saveImage(imageData,callback);
3-做一个HTTP POST请求到Web服务器API
URL url = new URL("http://myserver.com/my_images_folder/save_image.php");
URLConnection conn = url.openConnection();
conn.setReadTimeout(15000); //set a large time out since we're saving images
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response which contains the image file name
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
resa+=line;
}
wr.close();
System.out.println("close1");
rd.close();
System.out.println("Received: "+line);
4-将图像保存到文件服务器并返回图像文件名称
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])){
$imageData=$GLOBALS['HTTP_RAW_POST_DATA'];
//using a timestamp to create unique file names
//you can pass file name in params if you like instead
$fileName='User_Images_'.time().'.png';
// Remove the headers (data:,) part.
$filteredData=substr($imageData, strpos($imageData, ",")+1);
// Need to decode base64 encoded image
$unencodedData=base64_decode($filteredData);
$fp = fopen($fileName, 'wb');
fwrite($fp, $unencodedData);
fclose($fp);
$fileName2='http://myserver.com/my_images_folder/'.$fileName;
//return the file name
echo($fileName);
}else{
echo('no data posted');
}
现在,我对文件有一个很难的永久链接,我可以将它嵌入到电子邮件中,并用它来做其他事情。请参阅下面的参考3内嵌嵌入(这需要一个文件或URL,现在我们也很难URL到我们的Web服务器上的图像,我们可以通过电子邮件发送出来)
你的意思是“Base64编码图像”,而不是'64位图像'?实际上 –
是的......我想它了刚才......要编辑/回答这个问题 –