> ## 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 Object Post

> Questa documentazione fornisce una panoramica completa dell'endpoint POST /v1/objects 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>

<ParamField body="file" type="file" placeholder="myphone.png" required>
  Usa FormData. (multipart/form-data)
</ParamField>

<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="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 1 e 365 giorni.
</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 di frequenza e concorrenza

<Note>
  Il caricamento richiede un piano a pagamento.

  * I piani **Hobby** e **Standard** sono limitati a **1 caricamento al secondo**.
  * I piani **Pro** ed **Enterprise** **non** sono soggetti al limite al secondo: possono invece eseguire fino a **4 caricamenti contemporaneamente**.

  In tutti i piani a pagamento, un account può avere al massimo **4 caricamenti in corso simultaneamente**. Avviare un altro caricamento mentre 4 sono ancora in esecuzione restituisce `TOO_MANY_CONCURRENT_UPLOADS` (429).
</Note>

<Info>
  Per motivi di sicurezza, i file `.html` e `.svg` vengono sempre consegnati come download (serviti come `application/octet-stream`) invece di essere renderizzati inline.
</Info>

### 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="id" type="string">
      L'ID del file caricato.
    </ResponseField>

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

    <ResponseField name="prefix" type="string">
      Il prefisso sotto cui il file è stato memorizzato (riportato dalla query `prefix`; omesso quando non ne è stato inviato alcuno).
    </ResponseField>

    <ResponseField name="size" type="number">
      La dimensione del file caricato, in byte.
    </ResponseField>

    <ResponseField name="url" type="string">
      L'URL del file caricato. (File distribuito nella CDN di Square Cloud)
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url 'https://blob.squarecloud.app/v1/objects?name=myfile&prefix=images&expire=30' \
    --header 'Authorization: YOUR_API_KEY' \
    --form 'file=@./myphone.png'
  ```

  ```javascript JavaScript theme={null}
  import fs from 'node:fs';

  const form = new FormData();
  form.append('file', new Blob([fs.readFileSync('./myphone.png')]), 'myphone.png');

  const params = new URLSearchParams({
    name: 'myfile',
    prefix: 'images',
    expire: '30',
  });

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

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

  with open('myphone.png', 'rb') as f:
      response = requests.post(
          'https://blob.squarecloud.app/v1/objects',
          headers={'Authorization': 'YOUR_API_KEY'},
          params={'name': 'myfile', 'prefix': 'images', 'expire': 30},
          files={'file': ('myphone.png', f, 'image/png')},
      )
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null}
  {
      "status": "success",
      "response": {
          "id": "3155597145698959364/images/test_lxch4k7y-07ee.png",
          "name": "test",
          "prefix": "images",
          "size": 416230,
          "url": "https://public-blob.squarecloud.dev/3155597145698959364/images/test_lxch4k7y-07ee.png"
      }
  }
  ```
</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 1 to 365. (value in days).
      {
          "status": "error",
          "code": "INVALID_OBJECT_EXPIRE"
      }
      ```

      ```json SECURITY_HASH theme={null}
      // The provided security hash boolean is invalid.
      // Just set to true or false. 😅
      {
          "status": "error",
          "code": "INVALID_OBJECT_SECURITY_HASH"
      }
      ```

      ```json AUTO_DOWNLOAD theme={null}
      // The provided auto-download boolean is invalid.
      // Just set to true or false. 😅
      {
          "status": "error",
          "code": "INVALID_STORAGE_AUTO_DOWNLOAD"
      }
      ```
    </CodeGroup>

    ### Relativi al file

    <Info>La dimensione massima attuale del file è 100MB. In futuro prevediamo di aumentarla a 10GB. Per ora il limite è 100MB a causa di vincoli tecnici e di bilanciamento del carico.</Info>

    <CodeGroup>
      ```json INVALID_FILE theme={null}
      // The provided file is invalid.
      {
          "status": "error",
          "code": "INVALID_FILE"
      }
      ```

      ```json FILETYPE theme={null}
      // The provided file type is invalid.
      {
          "status": "error",
          "code": "INVALID_FILETYPE"
      }
      ```

      ```json FILE_TOO_SMALL theme={null}
      // The file size is too small (< 1kb).
      {
          "status": "error",
          "code": "FILE_TOO_SMALL"
      }
      ```
    </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.
      // Also returned when the account is on the free plan — uploading requires a paid plan.
      {
          "status": "error",
          "code": "ACCESS_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 409">
    ### Tipo di contenuto non valido

    <CodeGroup>
      ```json INVALID_CONTENT_TYPE theme={null}
      // This route only accepts multipart/form-data requests.
      {
          "status": "error",
          "code": "INVALID_CONTENT_TYPE"
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Status Code 413">
    ### Payload troppo grande

    <Info>La dimensione massima attuale del file è 100MB.</Info>

    <CodeGroup>
      ```json PAYLOAD_TOO_LARGE theme={null}
      // The uploaded file exceeds the maximum allowed size of 100 MB.
      {
          "status": "error",
          "code": "PAYLOAD_TOO_LARGE"
      }
      ```
    </CodeGroup>
  </Tab>

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

    <CodeGroup>
      ```json RATELIMIT theme={null}
      // Per-second upload limit reached (Hobby/Standard: max 1 upload per second).
      {
          "status": "error",
          "code": "RATELIMIT"
      }
      ```

      ```json TOO_MANY_CONCURRENT_UPLOADS theme={null}
      // Too many simultaneous uploads (max 4 in progress at a time per account).
      {
          "status": "error",
          "code": "TOO_MANY_CONCURRENT_UPLOADS"
      }
      ```
    </CodeGroup>
  </Tab>

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

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