skip to Main Content

I have an application who consist of a Node.js backend hosted on AWS and an Angular 2+ frontend. I am using the facebook graph API on the backend, however, when it comes to uploading things to facebook I’m getting into trouble.

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. 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.

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
  3. Do everything from the frontend using the javascript SDK

For me, the best solution would be 2. What are your opinions? Is there other solutions?

2

Answers


  1. 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).

    Your user Facebook credentials must never be sent to the backend, therefore do the upload to Facebook on client side using Facebook SDK.

    Doing it from client side also save you the infrastructure cost on the backend.

    Login or Signup to reply.
  2. 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. 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. 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. 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. Just use appsecret_proof: https://developers.facebook.com/docs/graph-api/securing-requests/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search