Este tema describe cómo cargar un archivo local a un bucket de Object Storage Service (OSS).
Ejemplos
A continuación se muestra un ejemplo de cómo cargar un archivo local llamado examplefile.txt a un bucket denominado examplebucket. El archivo cargado se almacena como un objeto con el nombre exampleobject.txt en 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')
Referencias
Para obtener más información sobre la operación de API que puede llamar para realizar una carga simple, consulte PutObject.