> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nonefivem.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Storage

> Upload files from NUI to NoCloud storage

## Methods

<Accordion title="NoCloud.isAvailable">
  Checks if the NoCloud service is available by pinging the service endpoint.

  ```typescript theme={null}
  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
</Accordion>

<Accordion title="NoCloud.storage.upload">
  Uploads a file to NoCloud storage.

  ```typescript theme={null}
  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
</Accordion>

<Accordion title="NoCloud.storage.getPresignedUrl">
  Obtains a presigned URL for uploading a file.

  ```typescript theme={null}
  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
</Accordion>

## Examples

### Upload a File

```typescript theme={null}
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

```typescript theme={null}
// 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:

```typescript theme={null}
try {
  const media = await NoCloud.storage.upload(file);
  console.log("Success:", media.url);
} catch (error) {
  console.error("Upload failed:", error);
}
```
