Cette rubrique explique comment charger un fichier local dans un bucket Object Storage Service (OSS).
Exemples
L'exemple de code suivant montre comment charger un fichier local nommé examplefile.txt dans un bucket nommé examplebucket. Le fichier chargé est stocké sous forme d'objet nommé exampleobject.txt dans 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')
Références
Pour plus d'informations sur l'opération API permettant d'effectuer un chargement simple, consultez PutObject.