简体   繁体   English

Node.js,Facebook Graph API-使用Node.js后端将文件上传到Facebook

[英]Node.js, Facebook Graph API - Upload file to facebook using a Node.js backend

I have an application who consist of a Node.js backend hosted on AWS and an Angular 2+ frontend. 我有一个应用程序,该应用程序由托管在AWS上的Node.js后端和Angular 2+前端组成。 I am using the facebook graph API on the backend, however, when it comes to uploading things to facebook I'm getting into trouble. 我在后端使用了facebook graph API,但是,将内容上传到facebook时遇到了麻烦。

If I want to upload a file, I need to upload it to my backend before, which will put it in an S3 bucket and then upload it from my backend to facebook. 如果要上传文件,则需要先将其上传到后端,这会将其放入S3存储桶中,然后从后端上传到Facebook。 This seems to be a little heavy for me and I am really suspicious that it is the correct way to do it. 这对我来说似乎有点沉重,我真的怀疑这是正确的方法。 Also, Facebook provides a javascript API that allows us to upload a file from a client to its platform, which seems less heavy. 此外,Facebook提供了一个javascript API,该API允许我们将文件从客户端上传到其平台,这看起来不那么繁重。

Right now, I see three solutions: 现在,我看到了三种解决方案:

  1. Continue doing everything on the backend 继续在后端做所有事情
  2. Only do upload operations on the client side using the javascript SDK, and everything else on the backend 仅使用javascript SDK在客户端执行上传操作,而在后端执行其他所有操作
  3. Do everything from the frontend using the javascript SDK 使用javascript SDK从前端做所有事情

For me, the best solution would be 2. What are your opinions? 对我来说,最好的解决办法是2。您对此有何看法? Is there other solutions? 还有其他解决方案吗?

If the file is created on the client, there is no need to send it to the server - you can just directly upload it to Facebook instead. 如果文件是在客户端上创建的,则无需将其发送到服务器-您可以直接将其上传到Facebook。 Although, if you need to store it on your own server anyway, you can do that first and let the server handle the upload to Facebook - uploading an URL of an image to Facebook is the easiest way. 虽然,如果仍然需要将其存储在自己的服务器上,则可以先执行该操作,然后让服务器将其上传到Facebook-将图像的URL上传到Facebook是最简单的方法。 If you don´t need the image on your server, this may help you: 如果您不需要服务器上的映像,这可以帮助您:

If the file is on the server already, there is no need to send it to the client before uploading it to Facebook. 如果文件已在服务器上,则无需在将其上传到Facebook之前将其发送到客户端。 In that case, i would do the upload server side. 在这种情况下,我将在上传服务器端进行操作。 If it´s about the security: There is absolutely no problem in sending Access Tokens to the server. 如果涉及安全性:将访问令牌发送到服务器绝对没有问题。 You can just use the JS SDK for login, send the Token to the server and do the upload on the server. 您可以只使用JS SDK进行登录,将令牌发送到服务器,然后在服务器上进行上传。 Just use appsecret_proof : https://developers.facebook.com/docs/graph-api/securing-requests/ 只需使用appsecret_proofhttps : //developers.facebook.com/docs/graph-api/securing-requests/

If you are using your end user identity on Facebook there is no benefit to use the backend here (except the fact that you need less Javascript on the page). 如果您在Facebook上使用最终用户身份,则在此处使用后端没有任何好处(除非您在页面上需要较少的Javascript)。

Your user Facebook credentials must never be sent to the backend , therefore do the upload to Facebook on client side using Facebook SDK. 您的用户Facebook凭据绝对不能发送到后端 ,因此请使用Facebook SDK在客户端上载到Facebook。

Doing it from client side also save you the infrastructure cost on the backend. 从客户端执行此操作还可以节省后端的基础结构成本。

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

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