Code Examples
Practical code examples and integration guides for the SolanaM platform
JavaScript Examples
Upload Image
async function uploadImage(file) {
const formData = new FormData();
formData.append('file', file);
const response = await fetch('https://api.solanam.com/v1/images/upload', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
},
body: formData
});
return await response.json();
}
// Usage
const fileInput = document.querySelector('input[type="file"]');
fileInput.addEventListener('change', async (e) => {
const file = e.target.files[0];
const result = await uploadImage(file);
console.log('Uploaded:', result);
});Convert Image Format
async function convertImage(imageId, targetFormat) {
const response = await fetch(
`https://api.solanam.com/v1/images/${imageId}/convert`,
{
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({ format: targetFormat })
}
);
return await response.json();
}
// Usage
const result = await convertImage('img_123', 'webp');
console.log('Converted:', result);TypeScript Examples
Type-Safe API Client
interface ImageUploadResponse {
success: boolean;
data: {
id: string;
url: string;
size: number;
format: string;
};
}
interface UploadOptions {
compress?: boolean;
quality?: number;
}
class SolanaMClient {
constructor(private apiKey: string) {}
async uploadImage(
file: File,
options?: UploadOptions
): Promise<ImageUploadResponse> {
const formData = new FormData();
formData.append('file', file);
if (options) {
formData.append('options', JSON.stringify(options));
}
const response = await fetch(
'https://api.solanam.com/v1/images/upload',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${this.apiKey}`
},
body: formData
}
);
return await response.json();
}
}
// Usage
const client = new SolanaMClient('YOUR_API_KEY');
const result = await client.uploadImage(file, {
compress: true,
quality: 90
});Python Examples
Python SDK Usage
import requests
from typing import Optional, Dict, Any
class SolanaMClient:
def __init__(self, api_key: str):
self.api_key = api_key
self.base_url = 'https://api.solanam.com/v1'
self.headers = {
'Authorization': f'Bearer {self.api_key}'
}
def upload_image(
self,
file_path: str,
options: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]:
with open(file_path, 'rb') as f:
files = {'file': f}
data = {'options': options} if options else {}
response = requests.post(
f'{self.base_url}/images/upload',
headers=self.headers,
files=files,
data=data
)
return response.json()
def convert_image(
self,
image_id: str,
target_format: str
) -> Dict[str, Any]:
response = requests.post(
f'{self.base_url}/images/{image_id}/convert',
headers={
**self.headers,
'Content-Type': 'application/json'
},
json={'format': target_format}
)
return response.json()
# Usage
client = SolanaMClient('YOUR_API_KEY')
result = client.upload_image('image.png', {
'compress': True,
'quality': 90
})
print(result)Integration Guides
React Integration
Learn how to integrate SolanaM API into your React applications with hooks and components.
View Guide →Vue.js Integration
Integrate SolanaM into Vue.js applications with composables and plugins.
View Guide →