Upload a file

How to upload a file using graphql

On Fairu, uploading one or more files is completed in three steps.

First, you need to let Fairu know how the upload should be handled.
There are two available upload methods:

  1. Standard – You receive a signed URL, which you can use to upload the file directly.
  2. Download – You provide our system with a URL where the file is hosted.
    This URL must be publicly accessible, without password protection or other access restrictions.

Here is an example showing the minimum requirements needed to create an upload link.

Query

mutation UploadFileToFairu {
  createFairuUploadLink(filename: "test.png") {
    id
    mime
    upload_url
    sync_url
  }
}

In the second step, you use the upload link to perform the actual upload.

It’s important to include the following header parameters in the upload request.
The MIME type can either be extracted from the upload request or defined by you - If you are not passing this two parameters to the upload - your request will be rejected.

"x-amz-acl": "public-read"
"Content-Type": "image/jpeg"

Here is a typical JavaScript example using axios to perform the upload with the required headers:

 
// Recieved from the first request
const entry = {
  upload_url: "https://...",
  sync_url: "https://...",
  mime: "image/jpeg"
}
 
await axios.put(
  entry.upload_url,
  file,
  {
    headers: {
      "x-amz-acl": "public-read",
      "Content-Type": entry.mime
    },
    onUploadProgress: (progressEvent) => {
      // Optionally handle progress here
      console.log(`Upload progress: ${(progressEvent.loaded / progressEvent.total) * 100}%`);
    }
  }
);

As soon as your upload to the upload URL is successful, perform a GET request to the sync URL to trigger further processing of the uploaded file.

If you don’t perform this request, our system will check at regular intervals (every few minutes) whether the file has been uploaded.
However, to immediately trigger the pipeline and make the file appear in the Explorer, you should explicitly call the sync URL with a GET request.

On this page