Photo Transcoder to WebP / Image Optimisation (Download Url)

FREEMIUM
By ozgurcagdas | Updated 2ヶ月前 | Video, Images
Health Check

N/A

Back to All Tutorials (2)

Axios example for all OPTION1 group (including this API)

“use strict”;

const axios = require(“axios”);

const {
YOUR_CALLBACK_URL, // your callback endpoint url like “https://your-backend.com/your-endpoint"
X_RAPID_API_KEY_a1, // your rapid api password for a1 …
X_RAPID_API_KEY_a2,
X_RAPID_API_KEY_a3,
X_RAPID_API_KEY_a4,
X_RAPID_API_KEY_a5,
} = require(”./testConfig");

const X_RAPID_API_HOST_a1 = “photo-transcoder-to-webp-image-optimisation-download-url.p.rapidapi.com”;
const X_RAPID_API_HOST_a2 = “gif-animated-photo-optimisation-transcoder-download-url.p.rapidapi.com”;
const X_RAPID_API_HOST_a3 = “audio-transcoder-compression-optimization-download-url.p.rapidapi.com”;
const X_RAPID_API_HOST_a4 = “video-mp4-transcoder-compression-optimization-download-url.p.rapidapi.com”;
const X_RAPID_API_HOST_a5 = “hls-video-transcoder-chunks-playlist-thumbs-download-url.p.rapidapi.com”;

/*
a1 = photo
a2 = animated phot (gif)
a3 = audio
a4 = mp4 video
a5 = hls video

filesList REQUIRED
thenOrCatchProcess OPTIONAL

check documantation for more details:
https://documenter.getpostman.com/view/7262582/2s9YJW5m6Q
*/

//PHOTO
const options_a1 = {
method: “POST”,
url: “https://” + X_RAPID_API_HOST_a1 + “/apifsp/transcoder/generate-download-link/photo”,
headers: {
“Content-Type”: “application/json”,
“X-RapidAPI-Key”: X_RAPID_API_KEY_a1,
“X-RapidAPI-Host”: X_RAPID_API_HOST_a1,
},
data: {
filesList: [
{
sourceInfo: {
sourceFileFormat: “PHOTO”,
sourceUrl: “https://picsum.photos/5000/3000.jpg”,
sourceFileExtension: “jpg”,
},
targetInfo: {
targetVersions: [
{
compressType: “PHOTO_WEBP”,
compressQuality: 60,
targetFileNameWithoutExtension_photo: “my-photo-xl”,
maxWidth: 2000,
maxHeight: 1500,
},
],
},
},
],
/*
OPTIONAL

thenOrCatchProcess: {
  callbackEndpointUrl: YOUR_CALLBACK_URL,
  callbackHeaders: {
    "x-any-of-your-callback-header": "any value...",
  },
  callbackDataExtras: {
    uploaderProfileId: 10074,
    uploadType: "PUBLIC",
    fileId: "a44",
    anyKey: "you can add any value for your callback like this... When transcode finish, this endpoint will be called. This 'thenOrCatchProcess' is optional. You can wait and try the download link manually.",
  },
},
*/

},
};
// animated image / gif
const options_a2 = {
method: “POST”,
url: “https://” + X_RAPID_API_HOST_a2 + “/apifsp/transcoder/generate-download-link/animated-photo”,
headers: {
“Content-Type”: “application/json”,
“X-RapidAPI-Key”: X_RAPID_API_KEY_a2,
“X-RapidAPI-Host”: X_RAPID_API_HOST_a2,
},
data: {
filesList: [
{
sourceInfo: {
sourceFileFormat: “ANIMATED_IMAGE”,
sourceUrl: “https://devcontentfilespublic.fullsepp.tv/_0test/color-gif-example.gif”,
sourceFileExtension: “gif”,
},
targetInfo: {
targetVersions: [
{
compressType: “ANIMATED_PHOTO_WEBP”,
compressQuality: 50,
targetFileNameWithoutExtension_animatedPhoto: “my-animated-image”,
maxWidth: 700,
maxHeight: 700,
},
],
},
extras: null,
},
],
/*
OPTIONAL

thenOrCatchProcess: {
  callbackEndpointUrl: YOUR_CALLBACK_URL,
  callbackHeaders: {
    "x-any-of-your-callback-header": "any value...",
  },
  callbackDataExtras: {
    uploaderProfileId: 10074,
    uploadType: "PUBLIC",
    fileId: "a44",
    anyKey: "you can add any value for your callback like this... When transcode finish, this endpoint will be called. This 'thenOrCatchProcess' is optional. You can wait and try the download link manually.",
  },
},
*/

},
};

// audio
const options_a3 = {
method: “POST”,
url: “https://” + X_RAPID_API_HOST_a3 + “/apifsp/transcoder/generate-download-link/audio”,
headers: {
“Content-Type”: “application/json”,
“X-RapidAPI-Key”: X_RAPID_API_KEY_a3,
“X-RapidAPI-Host”: X_RAPID_API_HOST_a3,
},
data: {
filesList: [
{
sourceInfo: {
sourceFileFormat: “AUDIO”,
sourceUrl: “https://devcontentfilespublic.fullsepp.tv/_0test/audio-test-jingle.mp3”,
sourceFileExtension: “mp3”,
},
targetInfo: {
targetVersions: [
{
compressType: “AAC_AUDIO”,
targetFileNameWithoutExtension_aacAudio: “transcodedFullAudio”,
},
],
},
extras: {
add_any_key_value_here: “you can use them in your callback”,
originalFileName: “audio-test-jingle.mp3”,
fileId: 250,
dbId: 123,
},
},
],
/*
OPTIONAL
thenOrCatchProcess: {
callbackEndpointUrl: YOUR_CALLBACK_URL,
callbackHeaders: {
“x-any-of-your-callback-header”: “any value…”,
},
callbackDataExtras: {
uploaderProfileId: 10074,
uploadType: “PUBLIC”,
fileId: “a44”,
anyKey: “you can add any value for your callback like this… When transcode finish, this endpoint will be called. This ‘thenOrCatchProcess’ is optional. You can wait and try the download link manually.”,
},
},
*/
},
};

// mp4 video
const options_a4 = {
method: “POST”,
url: “https://” + X_RAPID_API_HOST_a4 + “/apifsp/transcoder/generate-download-link/video-mp4”,
headers: {
“Content-Type”: “application/json”,
“X-RapidAPI-Key”: X_RAPID_API_KEY_a4,
“X-RapidAPI-Host”: X_RAPID_API_HOST_a4,
},
data: {
filesList: [
{
sourceInfo: {
sourceFileFormat: “VIDEO”,
sourceUrl: “https://devcontentfilespublic.fullsepp.tv/_0test/video+(1080p).mp4”,
sourceFileExtension: “mp4”,
},
targetInfo: {
targetVersions: [
{
compressType: “MP4_VIDEO”,
targetFileNameWithoutExtension_mp4Video: “mp4_version720p_transcodedFullVideo”,
targetFileNameWithoutExtension_videoThumbsFullSize: “mp4_version720p_thumbMaxSize”,
targetFileNameWithoutExtension_videoThumbs240p: “mp4_version720p_thumb240p”,
maxWidth: 1280,
maxHeight: 1280,
},
],
},
extras: {
fileId: 100,
ANY_KEY: “value for callback…”,
},
},
],
/*
OPTIONAL
thenOrCatchProcess: {
callbackEndpointUrl: YOUR_CALLBACK_URL,
callbackHeaders: {
“x-any-of-your-callback-header”: “any value…”,
},
callbackDataExtras: {
uploaderProfileId: 10074,
uploadType: “PUBLIC”,
fileId: “a44”,
anyKey: “you can add any value for your callback like this… When transcode finish, this endpoint will be called. This ‘thenOrCatchProcess’ is optional. You can wait and try the download link manually.”,
},
},
*/
},
};

// hls video
const options_a5 = {
method: “POST”,
url: “https://” + X_RAPID_API_HOST_a5 + “/apifsp/transcoder/generate-download-link/video-hls”,
headers: {
“Content-Type”: “application/json”,
“X-RapidAPI-Key”: X_RAPID_API_KEY_a5,
“X-RapidAPI-Host”: X_RAPID_API_HOST_a5,
},
data: {
filesList: [
{
sourceInfo: {
sourceFileFormat: “VIDEO”,
sourceUrl: “https://devcontentfilespublic.fullsepp.tv/_0test/video+(1080p).mp4”,
sourceFileExtension: “mp4”,
},
targetInfo: {
targetVersions: [
{
compressType: “HLS_VIDEO”,
targetFileNameWithoutExtension_hlsVideoChunk: “hls_version720p_videoChunk”,
targetFileNameWithoutExtension_videoThumbsFullSize: “hls_version720p_thumbMaxSize”,
targetFileNameWithoutExtension_videoThumbs240p: “hls_version720p_thumb240p”,
targetFileNameWithoutExtension_hlsVideoPlaylist: “hls_version720p_playlist”,
maxWidth: 1280,
maxHeight: 1280,
},
],
},
extras: {
originalFileName: “video (1080p).mp4”,
fileId: 1,
},
},
],
/*

OPTIONAL 
thenOrCatchProcess: {
  callbackEndpointUrl: YOUR_CALLBACK_URL,
  callbackHeaders: {
    "x-any-of-your-callback-header": "any value...",
  },
  callbackDataExtras: {
    uploaderProfileId: 10074,
    uploadType: "PUBLIC",
    fileId: "a44",
    anyKey: "you can add any value for your callback like this... When transcode finish, this endpoint will be called. This 'thenOrCatchProcess' is optional. You can wait and try the download link manually.",
  },
},
*/

},
};

const testFuntion = async (options) => {
try {
console.log("options: ", options);
const response = await axios.request(options);
console.log(response.data);
} catch (error) {
console.error(error);
}
};

/*
test one by one to prevent limit access.

// testFuntion(options_a1);
// testFuntion(options_a2);
// testFuntion(options_a3);
// testFuntion(options_a4);
// testFuntion(options_a5);

*/