This guide will help you get started with Get Pronto's asset hosting service in just a few minutes. You'll learn how to set up your account, install the SDK, and perform basic file operations.
Important: Your API key will only be shown once. Make sure to copy it to a secure location. For more information on API keys, see our Authentication guide.
Install the Get Pronto SDK using npm or yarn:
# Using npm
npm install @getpronto-io/getpronto-sdk
# Using yarn
yarn add @getpronto-io/getpronto-sdk
Create and initialize a Get Pronto client with your API key:
import GetProntoClient from "@getpronto-io/getpronto-sdk";
// Initialize the client with your API key
const client = new GetProntoClient({
apiKey: "YOUR_API_KEY"
});
Now that you have the client set up, let's upload a file:
try {
const result = await client.files.upload("./path/to/image.jpg");
console.log("File uploaded successfully:", result.file);
} catch (error) {
console.error("Upload failed:", error.message);
}
Retrieve a list of your uploaded files:
try {
const response = await client.files.list();
console.log("Files:", response.files);
console.log("Pagination:", response.pagination);
} catch (error) {
console.error("Failed to list files:", error.message);
}
Get Pronto allows you to transform images on-the-fly. Here's how to generate a URL for a resized image:
// Get the ID of an uploaded image
const fileId = "YOUR_FILE_ID";
// Generate a URL for a resized, grayscale version of the image
const imageUrl = await client.images
.transform(fileId)
.resize(800, 600)
.grayscale()
.quality(90)
.toURL();
console.log("Transformed image URL:", imageUrl);
// Use this URL in your application
document.getElementById('myImage').src = imageUrl;
Here's a complete example that ties everything together:
import GetProntoClient from "@getpronto-io/getpronto-sdk";
// Initialize the client
const client = new GetProntoClient({
apiKey: "YOUR_API_KEY"
});
async function uploadAndTransform() {
try {
// Upload a file
const uploadResult = await client.files.upload("./image.jpg");
console.log("File uploaded:", uploadResult.file);
// Get the file ID
const fileId = uploadResult.file.id;
// Generate a URL for the transformed image
const transformedUrl = await client.images
.transform(fileId)
.resize(300, 200)
.grayscale()
.toURL();
console.log("Transformed image URL:", transformedUrl);
// List all files
const listResult = await client.files.list();
console.log("Total files:", listResult.pagination.totalCount);
return {
originalFile: uploadResult.file,
transformedUrl
};
} catch (error) {
console.error("Error:", error.message);
}
}
// Run the example
uploadAndTransform();
Continue exploring our documentation with these related topics: