Skip to main content

Methods

Checks if the NoCloud service is available by pinging the service endpoint.
const available = await NoCloud.isAvailable();

if (available) {
  console.log("NoCloud service is available");
} else {
  console.log("NoCloud service is not available");
}
Returns
  • Promise<boolean> - true if the service is available
Uploads a file to NoCloud storage.
const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0];

const { id, url } = await NoCloud.storage.upload(file, {
  category: "user-uploads",
  userId: "12345"
});

console.log("Media ID:", id);
console.log("File uploaded to:", url);
Parameters
  • file: Blob | File - The file or blob to upload
  • metadata: Record<string, any> - Key-value pairs for custom metadata (optional)
Returns
  • id: string - Unique media ID
  • url: string - The media URL of the uploaded file
Obtains a presigned URL for uploading a file.
const { url, mediaUrl } = await NoCloud.storage.getPresignedUrl(
  "image/png", // Content type
  1024000, // File size in bytes
  {
    category: "screenshots",
    userId: "12345"
  }
);

// url: The presigned URL to upload the file
// mediaUrl: The final URL where the file will be accessible
Parameters
  • contentType: string - MIME type of the file (e.g., image/png)
  • size: number - File size in bytes
  • metadata: Record<string, any> - Key-value pairs for custom metadata (optional)
Returns
  • url: string - The presigned URL to upload the file
  • mediaUrl: string - The final URL where the uploaded file will be accessible

Examples

Upload a File

async function uploadFile(file: File) {
  try {
    const { id, url } = await NoCloud.storage.upload(file, {
      customMeta: "value",
      userId: "12345"
    });

    console.log("Media ID:", id);
    console.log("File uploaded to:", url);
  } catch (error) {
    console.error("Upload failed:", error);
  }
}

Upload Canvas Data

// Upload any Blob (e.g., canvas data)
const blob = await fetch(canvasDataUrl).then((r) => r.blob());

const { id, url } = await NoCloud.storage.upload(blob, {
  type: "canvas-export",
  timestamp: Date.now()
});

Error Handling

All methods throw errors when operations fail. Always wrap calls in try-catch blocks:
try {
  const media = await NoCloud.storage.upload(file);
  console.log("Success:", media.url);
} catch (error) {
  console.error("Upload failed:", error);
}