用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?

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

问题描述

从此 SO问题,我们的研究网络上的其他地方(像这样的Facebook doc链接),似乎有可能上传从canvas.toDataURL()到Facebook的图像直接 - 不在服务器上托管图像。

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.

推荐答案

可以在服务器上将画布上传为图片。我在两年前做了一个测试,你可以查找代码: 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天全站免登陆