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

# Blob Chunked Upload Init

> Questa documentazione fornisce una panoramica completa dell'endpoint POST /v1/objects/chunked dell'API Blob di SquareCloud.

<ParamField header="Authorization" type="string" placeholder="API Key" required>
  La chiave API del tuo account. Puoi trovarla nelle [impostazioni del tuo account](https://squarecloud.app/it/account/security).
</ParamField>

Chunked Init apre un caricamento a blocchi (chunked), il flusso per i file oltre il limite di 100 MB per singola richiesta, fino a **1 GiB**. Riserva la chiave dell'oggetto e restituisce un token `upload` opaco che accompagna le tre chiamate successive: [Chunked Part](/it/blob-reference/endpoint/chunked-part) per inviare ogni chunk, [Chunked Complete](/it/blob-reference/endpoint/chunked-complete) per sigillare l'oggetto e [Chunked Abort](/it/blob-reference/endpoint/chunked-abort) per annullare.

Non esiste **alcuna sessione lato server**: il token è l'intero stato del caricamento, quindi conservalo se l'upload deve sopravvivere a un ricaricamento della pagina. Un client che perde il proprio token non può annullare il caricamento, e i chunk memorizzati contano nel limite di **8 caricamenti aperti** dell'account finché il servizio non li recupera (circa 24 ore).

Il contratto della query è lo stesso di [Object Post](/it/blob-reference/endpoint/post), più `filename`: qui non c'è un envelope multipart, quindi l'estensione memorizzata deve arrivare dalla query string. Il caricamento richiede un piano a pagamento.

<ParamField query="name" type="string" placeholder="File Name" required>
  Una stringa che rappresenta il nome del file. (senza estensione)<br />Deve rispettare il pattern a-z, A-Z, 0-9 e \_. (da 3 a 32 caratteri)
</ParamField>

<ParamField query="filename" type="string" placeholder="Original filename">
  Il nome originale del file, estensione inclusa (es. `reads.fastq.gz`). L'estensione memorizzata viene derivata da esso, con fallback sul parametro `mime_type` e poi su `bin`.
</ParamField>

<ParamField query="prefix" type="string" placeholder="File Prefix">
  Una stringa che rappresenta il prefisso del file.<br />Deve rispettare il pattern a-z, A-Z, 0-9 e \_. (da 3 a 32 caratteri)
</ParamField>

<ParamField query="expire" type="number" placeholder="Expiration (days)">
  Un numero che indica il periodo di scadenza del file, compreso tra 7 e 1825 giorni (5 anni).
</ParamField>

<ParamField query="security_hash" type="boolean" placeholder="Security Hash">
  Imposta su true se è richiesto un hash di sicurezza.
</ParamField>

<ParamField query="auto_download" type="boolean" placeholder="Auto Download">
  Imposta su true se il file deve essere configurato per il download automatico.
</ParamField>

### Limiti

<Note>
  * Dimensione dell'oggetto: fino a **1 GiB** (1.073.741.824 byte).
  * Dimensione del chunk: **minimo 5 MB**, **massimo 32 MB** (l'ultimo chunk può essere più piccolo).
  * Chunk per oggetto: **205** (i numeri di parte vanno da 1 a 205).
  * Caricamenti aperti per account: **8** simultanei (`TOO_MANY_OPEN_UPLOADS`, 429).
  * Limite di frequenza: 5 aperture ogni 10 secondi, con blocco di 10 secondi oltre quel limite.

  Leggi i limiti dall'oggetto `chunk` nella risposta invece di codificarli a mano.
</Note>

### Risposta

<ResponseField name="status" type="string">
  Indica se la chiamata è andata a buon fine. "success" se riuscita, "error" in caso contrario.
</ResponseField>

<ResponseField name="response" type="object">
  <Expandable title="Toggle object">
    <ResponseField name="upload" type="string">
      Il token di caricamento opaco. Portalo in ogni chiamata successiva del flusso; è l'unico riferimento a questo caricamento.
    </ResponseField>

    <ResponseField name="id" type="string">
      L'ID (chiave) sotto cui l'oggetto verrà memorizzato.
    </ResponseField>

    <ResponseField name="name" type="string">
      Il nome del file.
    </ResponseField>

    <ResponseField name="prefix" type="string">
      Il prefisso sotto cui il file verrà memorizzato (`null` quando non ne è stato inviato alcuno).
    </ResponseField>

    <ResponseField name="url" type="string">
      L'URL pubblico CDN da cui l'oggetto verrà servito una volta completato.
    </ResponseField>

    <ResponseField name="chunk" type="object">
      I limiti del flusso chunked: `min_size` e `max_size` (byte del chunk), `max_parts` e `max_object_size` (byte totali).
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url 'https://blob.squarecloud.app/v1/objects/chunked?name=myfile&filename=reads.fastq.gz&expire=30' \
    --header 'Authorization: YOUR_API_KEY'
  ```

  ```javascript JavaScript theme={null}
  const params = new URLSearchParams({
    name: 'myfile',
    filename: 'reads.fastq.gz',
    expire: '30',
  });

  const response = await fetch(`https://blob.squarecloud.app/v1/objects/chunked?${params}`, {
    method: 'POST',
    headers: { Authorization: 'YOUR_API_KEY' },
  });

  const { response: upload } = await response.json();
  // persist upload.upload — it is the only handle to this upload
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://blob.squarecloud.app/v1/objects/chunked',
      headers={'Authorization': 'YOUR_API_KEY'},
      params={'name': 'myfile', 'filename': 'reads.fastq.gz', 'expire': 30},
  )
  upload = response.json()['response']
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null}
  {
    "status": "success",
    "response": {
      "upload": "MzE1NTU5NzE0NTY5ODk1OTM2NC9teWZpbGUtZXgzMC5mYXN0cS5negoyfjQ4WXcuLi4KMzA",
      "id": "3155597145698959364/myfile-ex30.fastq.gz",
      "name": "myfile",
      "prefix": null,
      "url": "https://public-blob.squarecloud.dev/3155597145698959364/myfile-ex30.fastq.gz",
      "chunk": {
        "min_size": 5242880,
        "max_size": 33554432,
        "max_parts": 205,
        "max_object_size": 1073741824
      }
    }
  }
  ```
</ResponseExample>

### Risoluzione dei problemi

<Tabs>
  <Tab title="Status Code 400">
    ### Relativi all'oggetto

    <CodeGroup>
      ```json NAME theme={null}
      // The provided object name is invalid.
      // Must adhere to the a to z, A to Z, 0 to 9, and _ pattern.
      {
          "status": "error",
          "code": "INVALID_OBJECT_NAME"
      }
      ```

      ```json PREFIX theme={null}
      // The provided object prefix is invalid.
      // Must adhere to the a to z, A to Z, 0 to 9, and _ pattern.
      {
          "status": "error",
          "code": "INVALID_OBJECT_PREFIX"
      }
      ```

      ```json EXPIRE theme={null}
      // The provided expiration value for the object is invalid.
      // Must be a number ranging from 7 to 1825. (value in days).
      {
          "status": "error",
          "code": "INVALID_OBJECT_EXPIRE"
      }
      ```

      ```json FILETYPE theme={null}
      // The file extension is malformed or too long.
      {
          "status": "error",
          "code": "INVALID_FILE_TYPE"
      }
      ```

      ```json BLOCKED_FILE_TYPE theme={null}
      // Executable/installer extensions (exe, msi, bat, apk, ...) are not accepted.
      {
          "status": "error",
          "code": "BLOCKED_FILE_TYPE"
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Status Code 401">
    ### Non autorizzato

    <CodeGroup>
      ```json ACCESS_DENIED theme={null}
      // The API key is missing or invalid. Set a valid key in the Authorization header.
      {
          "status": "error",
          "code": "ACCESS_DENIED"
      }
      ```

      ```json PERMISSION_DENIED theme={null}
      // The account has no active paid plan. Uploading to Blob Storage requires a paid plan.
      {
          "status": "error",
          "code": "PERMISSION_DENIED"
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Status Code 403">
    ### Quota di archiviazione superata

    <CodeGroup>
      ```json STORAGE_QUOTA_EXCEEDED theme={null}
      // You have exceeded your storage quota. Delete some files or upgrade your plan.
      {
          "status": "error",
          "code": "STORAGE_QUOTA_EXCEEDED"
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Status Code 429">
    ### Frequenza limitata

    <CodeGroup>
      ```json RATE_LIMITED theme={null}
      // Init rate limit reached (5 opens per 10s window, blocked for 10s).
      {
          "status": "error",
          "code": "RATE_LIMITED"
      }
      ```

      ```json TOO_MANY_OPEN_UPLOADS theme={null}
      // 8 chunked uploads already open. Complete or abort one first.
      {
          "status": "error",
          "code": "TOO_MANY_OPEN_UPLOADS"
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Status Code 500">
    ### Caricamento fallito

    <CodeGroup>
      ```json UPLOAD_FAILED theme={null}
      // Failed to open the chunked upload. Please try again later.
      {
          "status": "error",
          "code": "UPLOAD_FAILED"
      }
      ```
    </CodeGroup>
  </Tab>
</Tabs>
