File Api Github link

File Api Backend

Introduction

  • You need to edit your backend to pass the requests to File Api
  • NOTE! If you enabled Public on the File Api Panel you can skip these steps and you can use https://files-api.appysode.com/api/files/file?fileId=${FILE_ID} directly.

Getting Started

The Main Idea

  • You need to create a proxy that redirects the requests to https://files-api.appysode.com/api/files

Api

  • File Api uses /api/files for the file operations.
  • So, if you don't want to use /api/files for the proxy you need to send the requests to:
    • POST | https://files-api.appysode.com/api/files/upload?appId=${APP_ID}&appSecret=${APP_SECRET}
    • GET | https://files-api.appysode.com/api/files?appId=${APP_ID}&appSecret=${APP_SECRET}
    • GET | https://files-api.appysode.com/api/files/file?appId=${APP_ID}&appSecret=${APP_SECRET}&fileId=${FILE_ID}
    • DELETE |https://files-api.appysode.com/api/files/file?appId=${APP_ID}&appSecret=${APP_SECRET}&fileId=${FILE_ID}

Example

NodeJS

  • Note! You need to create the proxy before you create bodyParser. It breaks createProxyMiddleware
import express from "express";
import { createProxyMiddleware } from "http-proxy-middleware";
const app = express();
const FILE_API = "https://files-api.appysode.com";
const APP_ID = `THE ID YOU COPPIED FROM THE PANEL`;
const APP_SECRET = `THE SECRET YOU COPPIED FROM THE PANEL`;
const fileMiddleware = createProxyMiddleware({
  target: FILE_API,
  changeOrigin: true,
  logLevel: "debug",
  onProxyReq: (proxyReq) => {
    if (proxyReq.path.indexOf("?") > -1) {
      proxyReq.path += `&appId=${APP_ID}&appSecret=${APP_SECRET}`;
    } else {
      proxyReq.path += `?appId=${APP_ID}&appSecret=${APP_SECRET}`;
    }
  },
});
app.use(express.json());
app.use("/api/files", fileMiddleware);