const axios = require('axios');
const fs = require('fs');
const FormData = require('form-data');
// Load the image file
const filePath = '/path/to/your/image.png'; // Replace with your file path
const file = fs.createReadStream(filePath);
// Create a form data object
const form = new FormData();
form.append('file', file);
// Make the POST request
axios.post('https://api.fivemerr.com/v1/media/images', form, {
headers: {
...form.getHeaders(),
'Authorization': 'YOUR_API_KEY' // Replace with your API key
}
})
.then(response => {
console.log(response.data.url);
})
.catch(error => {
console.error(error);
});
Example with Python
import requests
# Load the image file
file_path = '/mnt/data/image.png' # Replace with your file path
files = {'file': open(file_path, 'rb')}
# Set the headers
headers = {
'Authorization': 'YOUR_API_KEY', # Replace with your API key
'Content-Type': 'multipart/form-data'
}
# Make the POST request
response = requests.post('https://api.fivemerr.com/v1/media/images', files=files, headers=headers)
# Print the response
print(response.json())
JSON Requests
Body
The request body should be a JSON string containing a key named file or data. Data should be encoded as base64 in the following format.
data:[<mediatype>][;base64],<data>
Example with Node.js (with Axios)
const axios = require('axios');
let data = JSON.stringify({
"file": "data:image/png;base64,iVBORw0KGgoAAA=="
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.fivemerr.com/v1/media/images',
headers: {
'Content-Type': 'application/json',
'Authorization': 'β’β’β’β’β’β’'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
x-www-form-urlencoded Requests
Body
The request body should be x-www-form-urlencoded containing a key named file or data. Data should be encoded as base64 in the following format.
data:[<mediatype>][;base64],<data>
Example with Node.js (with Axios)
const axios = require('axios');
const qs = require('qs');
let data = qs.stringify({
'file': 'data:image/png;base64,iVBORw0kJggg=='
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.fivemerr.com/v1/media/images',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'β’β’β’β’β’β’'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});