Questa pagina mostra come comporre oggetti Cloud Storage in un . Una richiesta di composizione accetta da 1 a 32 oggetti e crea un nuovo oggetto composito. L'oggetto composito è una concatenazione degli oggetti di origine nell'ordine in cui sono stati specificati nella richiesta.
Tieni presente quanto segue quando componi gli oggetti:
- Gli oggetti di origine non sono interessati dal processo di composizione. Se devono essere temporanei, devi eliminarli dopo aver completato la composizione.
- Poiché altre classi di archiviazione sono soggette a tariffe per l'eliminazione anticipata, deve sempre utilizzare Standard Storage per gli oggetti temporanei.
Ruoli obbligatori
Per ottenere le autorizzazioni necessarie per comporre gli oggetti, chiedi all'amministratore di concederti il ruolo IAM Utente oggetto archiviazione (roles/storage.objectUser
) nel bucket. Questo ruolo predefinito contiene
autorizzazioni necessarie per scrivere oggetti. Per vedere le autorizzazioni esatte
obbligatorie, espandi la sezione Autorizzazioni obbligatorie:
Autorizzazioni obbligatorie
storage.objects.create
storage.objects.delete
- Questa autorizzazione è necessaria solo se vuoi assegnare all'oggetto che stai componendo lo stesso nome di un oggetto già esistente nel bucket.
storage.objects.get
storage.objects.list
- Questa autorizzazione è necessaria solo se vuoi utilizzare i caratteri jolly per comporre oggetti con un prefisso comune senza dover elencare ogni oggetto separatamente nel comando Google Cloud CLI.
Se vuoi impostare una configurazione di conservazione per l'oggetto
che componi, dovrai disporre anche dell'autorizzazione storage.objects.setRetention
. Per ottenere questa autorizzazione, chiedi all'amministratore di concederti il ruolo Amministratore oggetto archiviazione (roles/storage.objectAdmin
) anziché il ruolo Utente oggetto archiviazione (roles/storage.objectUser
).
Puoi anche ottenere queste autorizzazioni con altri ruoli predefiniti o personalizzati.
Per informazioni sulla concessione dei ruoli ai bucket, consulta Utilizzare IAM con i bucket.
Creare un oggetto composito
Riga di comando
Utilizza il comando gcloud storage objects compose
:
gcloud storage objects compose gs://BUCKET_NAME/SOURCE_OBJECT_1 gs://BUCKET_NAME/SOURCE_OBJECT_2 gs://BUCKET_NAME/COMPOSITE_OBJECT_NAME
Dove:
BUCKET_NAME
è il nome del bucket che contiene gli oggetti di origine.SOURCE_OBJECT_1
eSOURCE_OBJECT_2
sono i nomi degli oggetti di origine da utilizzare nella composizione degli oggetti.COMPOSITE_OBJECT_NAME
è il nome che assegni al risultato della composizione dell'oggetto.
Librerie client
C++
Per ulteriori informazioni, consulta API Cloud Storage C++ documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
C#
Per ulteriori informazioni, consulta API Cloud Storage C# documentazione di riferimento.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
Go
Per ulteriori informazioni, consulta API Cloud Storage Go documentazione di riferimento.
Per autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
Java
Per ulteriori informazioni, consulta API Cloud Storage Java documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
Node.js
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage Node.js.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
PHP
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage PHP.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
Python
Per ulteriori informazioni, consulta API Cloud Storage Python documentazione di riferimento.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
Ruby
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage Ruby.
Per eseguire l'autenticazione su Cloud Storage, configura Credenziali predefinite dell'applicazione. Per maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
API REST
API JSON
Avere gcloud CLI installato e inizializzato, che consente generi un token di accesso per l'intestazione
Authorization
.Crea un file JSON contenente le seguenti informazioni:
{ "sourceObjects": [ { "name": "SOURCE_OBJECT_1" }, { "name": "SOURCE_OBJECT_2" } ], "destination": { "contentType": "COMPOSITE_OBJECT_CONTENT_TYPE" } }
Dove:
Utilizza
cURL
per chiamare l'API JSON con un RichiestaPOST
oggetto:curl -X POST --data-binary @JSON_FILE_NAME \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/o/COMPOSITE_OBJECT_NAME/compose"
Dove:
JSON_FILE_NAME
è il nome del file che hai creato nel passaggio precedente.BUCKET_NAME
è il nome del bucket che contiene gli oggetti di origine.COMPOSITE_OBJECT_NAME
è il nome che assegni al risultato della composizione dell'oggetto.
In caso di esito positivo, la risposta è una risorsa oggetto per l'oggetto composito risultante.
API XML
Avere installato e inizializzato l'interfaccia a riga di comando gcloud, che consente di generare un token di accesso per l'intestazione
Authorization
.Crea un file XML che contenga le seguenti informazioni:
<ComposeRequest> <Component> <Name>SOURCE_OBJECT_1</Name> </Component> <Component> <Name>SOURCE_OBJECT_2</Name> </Component> </ComposeRequest>
Dove:
SOURCE_OBJECT_1
eSOURCE_OBJECT_2
sono i nomi degli oggetti di origine da utilizzare nella composizione degli oggetti.
Utilizza
cURL
per chiamare l'API XML con unPUT
Oggetto richiesta ecompose
parametro della stringa di query:curl -X PUT --data-binary @XML_FILE_NAME \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: COMPOSITE_OBJECT_CONTENT_TYPE" \ "https://storage.googleapis.com/BUCKET_NAME/COMPOSITE_OBJECT_NAME?compose"
Dove:
XML_FILE_NAME
è il nome del file creato nel passaggio precedente.COMPOSITE_OBJECT_CONTENT_TYPE
è il Content-Type dell'oggetto composito risultante.BUCKET_NAME
è il nome del bucket che contiene gli oggetti di origine.COMPOSITE_OBJECT_NAME
è il tuo nome dando al risultato della composizione dell'oggetto.
In caso di esito positivo, viene restituito un corpo della risposta vuoto.
Passaggi successivi
- Scopri di più sulla composizione degli oggetti.
- Scopri come utilizzare le condizioni preliminari per le richieste per prevenire le condizioni di gara.