2012-05-31 24 views
0

我运行在Java中对GWT + GAE应用在谷歌应用程序引擎发送HTML5画布图像作为嵌入图像的电子邮件

我想找到自己的HTML5画布的(GWT Canvas类)中的内容,并让他们保存在永久和网络寻址文件

例子:http://myserver.com/images/image_434.png

当我使用canvas2.toDataUrl()...

1是否有可能这些内容发布到PHP在画布内容Web API通过HTTP请求a然后使用PHP(在我的服务器上)解码64位图像并将其写入文件并返回固定链接。

或者

2-是它在某种程度上能够RPC的图像数据发送到服务器侧,将其保存到文件中(ImageIO的被阻止在GAE),然后嵌入该文件以某种方式在电子邮件和电子邮件它到我的服务器。

我很困惑,因为:

方法1:我怀疑会工作,张贴那么久,我不知道一个参数,但我有一种直觉,将无法正常工作。方法2:如果我能弄清楚如何在没有固定文件URL的情况下在邮件中嵌入图像(通过以某种方式直接将流写入消息体)可能会起作用。

正如你所看到的,我通常对此感到困惑。这样做不应该很难,我不能成为唯一一个尝试这样做的人......尽管我现在一直在寻找3天。

由于

+1

你的意思是“Base64编码图像”,而不是'64位图像'?实际上 –

+0

是的......我想它了刚才......要编辑/回答这个问题 –

回答

0
  • 客户端侧(GWT):

1-得到base64编码图像URI

String imageData= canvas2.toDataUrl(); 

2-通过RPC调用向发送的图像数据服务器端

jdbc.saveImage(imageData,callback); 
  • 服务器端(GAE):

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); 
  • 服务器端(你的Web服务器-php API):

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服务器上的图像,我们可以通过电子邮件发送出来)

+0

参考1:http://permadi.com/blog/2010/10/html5-saving-canvas-image-data-using -php和 - AJAX /#viewSource –

+0

文献2:http://www.exampledepot.com/egs/java.net/post.html –

+0

文献3:http://java.sun.com/developer/onlineTraining/ JavaMail的/ contents.html#IncludingImagesWithHTML –

相关问题