上传照片与Facebook Graph API和JavaScript:将canvas图像转换为multipart / form-data作为POST正文? [英] Upload photo with Facebook Graph API and JavaScript: convert canvas image to multipart/form-data as POST body?

查看:383
本文介绍了上传照片与Facebook Graph API和JavaScript:将canvas图像转换为multipart / form-data作为POST正文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从这个 SO问题的主题和我们的研究网上其他地方(像这个Facebook doc链接),似乎可以上传

From this SO question on the topic and from our research elsewhere on the web (like this Facebook doc link), it seems possible to upload an image from canvas.toDataURL() to Facebook directly -- without hosting the image on a server.

我们面临的问题是如何转换base64编码的数据从toDataURL()到Facebook期望的multipart / form-data。这是可能的在客户端使用JavaScript和 jQuery.post()?如果没有,我们可以尝试保存在服务器上的图像首先,但更喜欢绕过这一步,如果可能的话,做一切从客户端。

The problem we're facing is how to convert the base64-encoded data from toDataURL() into the multipart/form-data that Facebook expects. Is this possible on the client side with JavaScript and jQuery.post()? If not, we can resort to saving the image on a server first but prefer bypassing this step if possible and doing everything from the client.

这是一个PhoneGap应用程序。

This is for a PhoneGap app.

推荐答案

可以在服务器上将画布上传为图片。我在2年前做过测试,您可以查看代码: http://standupweb.net/canvas/ swSaveCanvas.php

Uploading a canvas as a picture on the server is possible. I did a test 2 years ago, you can look up the code: http://standupweb.net/canvas/swSaveCanvas.php

这是使用mootools,但它真的不需要,保存函数中的一切都是原生的JS代码。

That was using mootools, but it is really not needed there, everything in the save function is native JS code.

与Facebook整合不应该是一个大问题

Integrating that with facebook should not be a big problem

这篇关于上传照片与Facebook Graph API和JavaScript:将canvas图像转换为multipart / form-data作为POST正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆