Este tópico descreve como fazer upload de um arquivo local para um bucket do Object Storage Service (OSS).
Exemplos
O código a seguir mostra como fazer upload de um arquivo local chamado examplefile.txt para um bucket chamado examplebucket. O arquivo enviado é armazenado como um objeto chamado exampleobject.txt no OSS.
require 'aliyun/oss'
client = Aliyun::OSS::Client.new(
# Set the endpoint. This example uses the China (Hangzhou) region. Specify the endpoint for your actual region.
endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
# Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
access_key_id: ENV['OSS_ACCESS_KEY_ID'],
access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)
# Specify the bucket name. For example, examplebucket.
bucket = client.get_bucket('examplebucket')
# Upload the file.
bucket.put_object('exampleobject.txt', :file => 'D:\\localpath\\examplefile.txt')
Referências
Para obter mais informações sobre a operação de API usada para upload simples, consulte PutObject.