NoCloud SDK for CFX NUI (FiveM/RedM) - browser environment only
npm install @nocloud/cfx-nui
---
NoCloud CFX NUI SDK provides a TypeScript client library for interacting with NoCloud services from CFX NUI (browser) contexts. This package enables NUI applications to check service availability, obtain presigned upload URLs, and upload files directly to NoCloud's serverless storage.
- ☁️ Cloud Storage - Upload files directly from NUI to NoCloud's serverless storage
- 🔒 Signed URLs - Secure uploads with pre-signed URLs
- ⚡ Zero Dependencies - Lightweight, self-contained library
- 🛠️ TypeScript First - Full type safety for NUI applications
- 🎯 Simple API - Clean, promise-based interface
This package is designed to be used in CFX NUI projects.
``bash`
bun add @nocloud/cfx-nui
`typescript`
import { NoCloud } from "@nocloud/cfx-nui";
`typescript`
const isAvailable = await NoCloud.isAvailable();
if (isAvailable) {
console.log("NoCloud service is available");
}
`typescript
async function uploadFile(file: File) {
try {
// Check if NoCloud is available
if (await NoCloud.isAvailable()) {
// Upload with optional metadata
const mediaUrl = await NoCloud.storage.upload(file, {
customMeta: "value",
userId: "12345"
});
console.log("File uploaded to:", mediaUrl);
} else {
console.error("NoCloud service is not available");
}
} catch (error) {
console.error("Upload failed:", error);
}
}
`
`typescript
const { url, mediaUrl } = await NoCloud.storage.getPresignedUrl(
"image/png", // Content type
1024000, // File size in bytes
{
// Optional metadata
category: "screenshots",
userId: "12345"
}
);
// url: The presigned URL for uploading
// mediaUrl: The final URL where the file will be accessible
`
`typescript`
// Upload any Blob (e.g., canvas data)
const blob = await fetch(canvasDataUrl).then((r) => r.blob());
const mediaUrl = await NoCloud.storage.upload(blob, {
type: "canvas-export",
timestamp: Date.now()
});
Checks if the NoCloud service is available by pinging the service endpoint.
Returns: Promise
Example:
`typescript`
const available = await NoCloud.isAvailable();
Obtains a presigned URL for uploading a file.
Parameters:
- contentType (string): The MIME type of the file (e.g., 'image/png')size
- (number): The file size in bytesmetadata
- (Record
Returns: Promise<{ mediaUrl: string; url: string }>
- url: The presigned URL to upload the filemediaUrl
- : The final URL where the uploaded file will be accessible
Example:
`typescript`
const { url, mediaUrl } = await NoCloud.storage.getPresignedUrl(
"image/jpeg",
50000
);
Uploads a file to NoCloud storage.
Parameters:
- file (Blob | File): The file or blob to uploadmetadata
- (Record
Returns: Promise - The media URL of the uploaded file
Example:
`typescript`
const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0];
const url = await NoCloud.storage.upload(file, { category: "user-uploads" });
All methods throw errors when operations fail. Always wrap calls in try-catch blocks:
`typescript``
try {
const mediaUrl = await NoCloud.storage.upload(file);
console.log("Success:", mediaUrl);
} catch (error) {
console.error("Upload failed:", error);
}
MIT © NoCloud