Questa pagina mostra come copiare, rinominare e spostare oggetti all'interno e tra i bucket in Cloud Storage.
Tieni presente che, anche se alcuni strumenti di Cloud Storage eseguono lo spostamento di un oggetto o l'operazione di ridenominazione sembra essere un'operazione univoca, si tratta sempre di un'operazione di copia seguita da un'operazione di eliminazione dell'oggetto originale, poiché gli oggetti immutable.
Copiare un oggetto
Per copiare un oggetto in uno dei bucket Cloud Storage:
Console
- Nella console Google Cloud, vai alla pagina Bucket di Cloud Storage.
Nell'elenco dei bucket, fai clic sul nome del bucket che contiene l'oggetto che vuoi copiare.
Viene visualizzata la pagina Dettagli bucket con la scheda Oggetti selezionata.
Accedi all'oggetto, che potrebbe trovarsi in una cartella.
Fai clic sul menu Extra dell'oggetto (more_vert) associato all'oggetto.
Fai clic su Copia.
Viene visualizzato il riquadro Copia oggetto.
Nel campo Destinazione, digita il nome del bucket di destinazione. e il nome dell'oggetto copiato.
In alternativa, puoi fare clic su Sfoglia per selezionare la destinazione, ma le opzioni di ricerca sono limitate ai bucket nel progetto attuale.
Fai clic su Copia.
Per scoprire come ottenere informazioni dettagliate sugli errori relativi alle operazioni di Cloud Storage non riuscite nella console Google Cloud, consulta la sezione Risoluzione dei problemi.
Riga di comando
Utilizza il comando gcloud storage cp
:
gcloud storage cp gs://SOURCE_BUCKET_NAME/SOURCE_OBJECT_NAME gs://DESTINATION_BUCKET_NAME/NAME_OF_COPY
Dove:
SOURCE_BUCKET_NAME
è il nome del bucket contenente l'oggetto che vuoi copiare. Ad esempio,my-bucket
.SOURCE_OBJECT_NAME
è il nome dell'oggetto che vuoi copiare. Ad esempio,pets/dog.png
.DESTINATION_BUCKET_NAME
è il nome del separatore in cui vuoi copiare l'oggetto. Ad esempio:another-bucket
.NAME_OF_COPY
è il nome che vuoi assegnare alla copia dell'oggetto. Ad esempio,shiba.png
.
Se l'esito è positivo, la risposta è simile al seguente esempio:
Copying gs://example-bucket/file.txt to gs://other-bucket/file-copy.txt Completed files 1/1 | 164.3kiB/164.3kiB
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 maggiori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
Go
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage Go.
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 API Cloud Storage Node.js 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.
PHP
Per ulteriori informazioni, consulta API Cloud Storage PHP 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.
Python
Per ulteriori informazioni, consulta API Cloud Storage Python 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.
Ruby
Per ulteriori informazioni, consulta API Cloud Storage Ruby 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.
API REST
API JSON
Avere gcloud CLI installato e inizializzato, che consente generi un token di accesso per l'intestazione
Authorization
.Utilizza
cURL
per chiamare l'API JSON con una richiesta diPOST
oggetto:curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Length: 0" \ "https://storage.googleapis.com/storage/v1/b/SOURCE_BUCKET_NAME/o/SOURCE_OBJECT_NAME/rewriteTo/b/DESTINATION_BUCKET_NAME/o/NAME_OF_COPY"
Dove:
SOURCE_BUCKET_NAME
è il nome del separato contenente l'oggetto che vuoi copiare. Ad esempio,my-bucket
.SOURCE_OBJECT_NAME
è il nome con codifica URL dell'oggetto da copiare. Ad esempio,pets/dog.png
, Codificato come URLpets%2Fdog.png
.DESTINATION_BUCKET_NAME
è il nome di nel bucket in cui vuoi copiare l'oggetto. Ad esempio,another-bucket
.NAME_OF_COPY
è il nome con codifica URL che vuoi assegnare alla copia dell'oggetto. Ad esempio,shiba.png
.
Poiché il metodo
rewrite
copia i dati in blocchi di dimensioni limitate, la copia potrebbe richiedere più richieste, in particolare per oggetti di grandi dimensioni.Ad esempio, la seguente risposta a una richiesta
rewrite
indica che devi effettuare altre richiesterewrite
:{ "kind": "storage#rewriteResponse", "totalBytesRewritten": 1048576, "objectSize": 10000000000, "done": false, "rewriteToken": TOKEN_VALUE }
Utilizza
rewriteToken
in una richiesta successiva per continuare a copiare i dati:curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Length: 0" \ -d '{"rewriteToken": "TOKEN_VALUE"}' \ "https://storage.googleapis.com/storage/v1/b/SOURCE_BUCKET_NAME/o/SOURCE_OBJECT_NAME/rewriteTo/b/DESTINATION_BUCKET_NAME/o/NAME_OF_COPY"
Dove:
TOKEN_VALUE
è il valorerewriteToken
restituito nella richiesta precedente.- Tutti gli altri valori corrispondono a quelli utilizzati nella richiesta precedente.
Quando l'oggetto è completamente copiato, l'ultima risposta ha una proprietà
done
impostata sutrue
, non è presente una proprietàrewriteToken
e i metadati della copia sono inclusi nella proprietàresource
.{ "kind": "storage#rewriteResponse", "totalBytesRewritten": 10000000000, "objectSize": 10000000000, "done": true, "resource": objects Resource }
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
.Utilizza
cURL
per chiamare l'API XML con un RichiestaPUT
Oggetto:curl -X PUT \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "x-goog-copy-source: SOURCE_BUCKET_NAME/SOURCE_OBJECT_NAME" \ "https://storage.googleapis.com/DESTINATION_BUCKET_NAME/NAME_OF_COPY"
Dove:
SOURCE_BUCKET_NAME
è il nome del bucket contenente l'oggetto che vuoi copiare. Ad esempio,my-bucket
.SOURCE_OBJECT_NAME
è il nome dell'oggetto che vuoi copiare. Ad esempio,pets/dog.png
.DESTINATION_BUCKET_NAME
è il nome di nel bucket in cui vuoi copiare l'oggetto. Ad esempio:another-bucket
.NAME_OF_COPY
è il nome con codifica URL che vuoi assegnare alla copia dell'oggetto. Ad esempio,shiba.png
.
Spostare o rinominare un oggetto
Per spostare un oggetto in Cloud Storage tra bucket, oppure rinomina un oggetto all'interno di un bucket:
Console
- Nella console Google Cloud, vai alla pagina Bucket di Cloud Storage.
Nell'elenco dei bucket, fai clic sul nome del bucket contenente l'oggetto che vuoi spostare o rinominare.
Viene visualizzata la pagina Dettagli bucket con la scheda Oggetti selezionata.
Accedi all'oggetto, che potrebbe trovarsi in una cartella.
Fai clic sul menu Extra dell'oggetto (more_vert) associato all'oggetto.
Se vuoi assegnare un nuovo nome all'oggetto nello stesso bucket, fai clic su Rinomina.
Nella finestra di overlay visualizzata, inserisci un nuovo nome per l'oggetto.
Fai clic su Rinomina.
Se vuoi spostare l'oggetto in un altro bucket, fai clic su Sposta.
Nella finestra di overlay visualizzata, fai clic su Sfoglia.
Seleziona la destinazione dell'oggetto che stai spostando.
Fai clic su Seleziona.
Fai clic su Sposta.
Scopri come ottenere informazioni dettagliate sugli errori relativi a Cloud Storage non riusciti nella console Google Cloud, vedi Risoluzione dei problemi.
Riga di comando
Utilizza il comando gcloud storage mv
:
gcloud storage mv gs://SOURCE_BUCKET_NAME/SOURCE_OBJECT_NAME gs://DESTINATION_BUCKET_NAME/DESTINATION_OBJECT_NAME
Dove:
SOURCE_BUCKET_NAME
è il nome del bucket contenente l'oggetto che vuoi spostare o rinominare. Ad esempio,my-bucket
.SOURCE_OBJECT_NAME
è il nome dell'oggetto che vuoi spostare o rinominare. Ad esempio,pets/dog.png
.DESTINATION_BUCKET_NAME
è il nome del bucket che memorizza l'oggetto spostato o rinominato. Ad esempio,another-bucket
.DESTINATION_OBJECT_NAME
è il nome che vuoi dopo lo spostamento o la ridenominazione dell'oggetto. Ad esempio,shiba.png
.
Se l'esito è positivo, la risposta è simile al seguente esempio:
Copying gs://example-bucket/old-file.txt to gs://new-bucket/new-file.txt Removing gs://example-bucket/old-file.txt... Completed files 1/1 | 164.3kiB/164.3kiB
Librerie client
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.
C#
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage C#.
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.
Go
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage Go.
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 la documentazione di riferimento dell'API Cloud Storage Java.
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.
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 autenticarti a Cloud Storage, configura le credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
Python
Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Cloud Storage Python.
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.
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 ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
API REST
API JSON
Per spostare o rinominare un oggetto utilizzando direttamente l'API JSON, prima crea una copia dell'oggetto con le proprietà che ti interessano e poi elimina l'oggetto originale.
API XML
Per spostare o rinominare un oggetto direttamente utilizzando l'API XML, devi prima creare una copia dell'oggetto che ha le proprietà che desideri e quindi elimina l'oggetto originale.
Ti consigliamo di utilizzare Storage Transfer Service per spostare più di 1 TB di dati tra i bucket.
Passaggi successivi
- Modifica la classe di archiviazione di un oggetto.
- Modifica i metadati di un oggetto.
- Rendi oggetti e bucket accessibili pubblicamente.
- Scopri di più sui requisiti di denominazione degli oggetti.
- Scopri di più sull'utilizzo delle condizioni preliminari per le richieste per prevenire le condizioni di gara.