My App

Presigned URLs

Secure client-side uploads without exposing your API token

Presigned URLs allow secure client-side uploads without exposing your API token. This is essential for scenarios like FiveM NUI uploads or browser-based applications.

Never expose your API token in client-side code. Always use presigned URLs for direct client uploads.

Request the presigned URL

Start by performing a GET request on the server. This needs to contain the endpoint and your API token.

The ?fileType param can be image, audio or video.

We plan to remove this ?fileType param in our next version of the API.

curl --request GET \
  --url 'https://fmapi.net/api/v2/presigned-url?fileType=image' \
  --header 'Authorization: YOUR_API_TOKEN' \
const options = {
  method: 'GET',
  headers: {
    'User-Agent': 'YOUR_SERVICE',
    Authorization: 'YOUR_API_TOKEN'
  }
};

fetch('https://fmapi.net/api/v2/presigned-url?fileType=image', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));

You will then get a response that looks like this:

{
  "presignedUrl": "https://fmapi.net/api/v2/presigned-url/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

This is the url that you will be using in order to upload the file.

Uploading files

Once you have this URL, you can then use it to upload a file like you might previously have done, but without a Authorization header.

curl --request POST \
  --url https://fmapi.net/api/v2/presigned-url/iCyMnIkzF423RQr88Hppo \
  --header 'Content-Type: multipart/form-data' \
  --form file=path/to/your/file.png
const axios = require('axios');
const fs = require('fs');
 
const url = 'https://fmapi.net/api/v2/presigned-url/iCyMnIkzF423RQr88Hppo';
 
const formData = new FormData();
 
formData.append('file', fs.createReadStream('image.png'));
// Optional metadata field (JSON string)
formData.append("metadata", JSON.stringify({
    name: 'My image',
    description: 'This is my image',
}));
 
axios.post(url, formData).then(res => {
    console.log(res.url);
}).catch(err => {
    console.error(err);
});

Response

{
  "id": "7F9pGhN8qwErT1vx5aZk",
  "url": "https://i.fmfile.com/7F9pGhN8qwErT1vx5aZk.jpg"
}