Copiar um objeto usando multipart upload
Os exemplos nesta seção mostram como copiar objetos maiores que 5 GB usando a API de multipart upload. Copie objetos menores que 5 GB em uma única operação. Para obter mais informações, consulte Copiar, mover e renomear objetos.
Para copiar um objeto usando a API de baixo nível, faça o seguinte:
-
Inicie um multipart upload chamando o método
AmazonS3Client.initiateMultipartUpload()
. -
Salve o ID de upload do objeto de resposta retornado pelo método
AmazonS3Client.initiateMultipartUpload()
. Você fornece esse ID de upload para cada operação do upload de parte. -
Copie todas as partes. Para cada parte que você precisar copiar, crie uma nova instância da classe
CopyPartRequest
. Forneça as informações da parte, incluindo a origem e os nomes do bucket de destino, as chaves de objeto de origem e de destino, o ID de upload, os locais dos primeiros e últimos bytes da parte, e o número da parte. -
Salve as respostas das chamadas de método
AmazonS3Client.copyPart()
. Cada resposta inclui o valorETag
e o número da parte para a parte cujo upload foi feito. Você precisa dessas informações para concluir o multipart upload. -
Chame o método
AmazonS3Client.completeMultipartUpload()
para concluir a operação de cópia.
As seções a seguir na Referência de APIs do Amazon Simple Storage Service descrevem a API REST para multipart upload. Para copiar um objeto existente, use a API para upload de parte (cópia) e especifique o objeto de origem adicionando o cabeçalho de solicitação x-amz-copy-source
na solicitação.
Use essas APIs para fazer suas próprias solicitações REST ou use um dos SDKs que fornecemos. Para obter mais informações sobre como usar o multipart upload com a AWS CLI, consulte Usar a AWS CLI. Para obter mais informações sobre os SDKs, consulte Suporte do AWS SDK para upload fracionado.