繁体   English   中英

通过Google App引擎将HTML5 Canvas图像作为嵌入式图像发送到电子邮件中

[英]Sending HTML5 Canvas image as embedded image in email over google app engine

我正在GWT + GAE上用Java运行应用程序

我想获取我的html5 Canvas(GWT Canvas类)的内容,并将其保存在一个永久的Web可寻址文件中

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

当我使用canvas2.toDataUrl()获取画布内容时...

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

要么

2-是否可以通过某种方式将RPC的图像数据发送到服务器端,将其保存到文件(ImageIO在GAE中被阻止),然后以某种方式将该文件嵌入到电子邮件中并通过电子邮件发送给我的服务器。

我很困惑,因为:

方法1:我不确定是否可以正常工作,并发布了一个很长的参数,我不确定,但是我有一种直觉,认为那将不起作用。

方法2:如果我能弄清楚如何在没有坚实的文件URL的情况下将图像嵌入邮件(通过将流直接写入消息正文以某种方式)可能会起作用。

如您所见,我对此普遍感到困惑。 做到这一点应该不难,而且我不是唯一尝试这样做的人……尽管我现在已经搜索了3天。

谢谢

  • 客户端(GWT):

1-获取base64编码的图像URI

String imageData= canvas2.toDataUrl();

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

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

3-向您的Web服务器API发出HTTP发布请求

        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,因为我们在Web服务器上具有指向图像的硬URL,因此可以通过电子邮件发送出去)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM