Tüm Ürünler
Search
Belge Merkezi

Object Storage Service:Upload callbacks

Son Güncelleme:Oct 01, 2026

Bir nesne yüklendiğinde Object Storage Service (OSS), uygulama sunucusu için bir geri arama süreci başlatabilir. Yükleme geri aramalarını yapılandırmak için OSS'e gönderilen yükleme isteğine gerekli geri arama parametrelerini eklemeniz yeterlidir.

Not

OSS'in callbackSNI gönderip göndermeyeceği, geri arama parametrelerinin yapısına bağlıdır. Daha fazla bilgi için bkz. Geri Arama.

Kullanım notu

Yükleme geri aramasını yapılandırmadan önce yükleme geri arama özelliğini tanıyın. Daha fazla bilgi için bkz. Yükleme Geri Araması.

Örnekler

Aşağıdaki örnek kod, examplefile.txt adlı yerel bir dosyanın examplebucket adlı bir pakete yüklenmesi sırasında yükleme geri aramalarının nasıl yapılandırılacağını gösterir. Yerel dosya yüklendikten sonra OSS'teki nesnenin adı exampleobject.txt olur.

const OSS = require("ali-oss");

var path = require("path");

const client = new OSS({
  // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou. 
  region: "yourregion",
  // Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the name of the bucket. 
  bucket: "examplebucket",
});

const options = {
  callback: {
    // Specify the address of the callback server that receives the callback request. Example: http://oss-demo.aliyuncs.com:23450. 
    url: "http://oss-demo.aliyuncs.com:23450",
    // (Optional) Specify the Host field included in the callback request header. 
    //host: 'yourCallbackHost',
    // Specify the body of the callback request. 
    body: "bucket=${bucket}&object=${object}&var1=${x:var1}&var2=${x:var2}",
    // Specify Content-Type in the callback request. 
    contentType: "application/x-www-form-urlencoded",
    // Specifies whether OSS sends Server Name Indication (SNI) to the origin address specified by callbackUrl when a callback request is initiated from the client.
    callbackSNI: true,
    // Configure custom parameters for the callback request. 
    customValue: {
      var1: "value1",
      var2: "value2",
    },
  },
};

async function put() {
  try {
    // Specify the full paths of the object and the local file. Do not include the bucket name in the full path of the object. 
    // By default, if you do not specify the path of the local file, the file is uploaded from the local path of the project to which the sample program belongs. 
    let result = await client.put(
      "exampleobject.txt",
      path.normalize("/localpath/examplefile.txt"),
      options
    );
    console.log(result);
  } catch (e) {
    console.log(e);
  }
}

put();

İlgili konular

  • Yükleme geri aramalarını yapılandırmak için kullanılan tam örnek kodu görüntülemek üzere GitHub adresini ziyaret edin.

  • Yükleme geri aramalarını yapılandırmak için çağırabileceğiniz API işlemi hakkında daha fazla bilgi için bkz. Geri Arama.

  • Yükleme geri araması hatalarının nedenleri ve çözümleri hakkında daha fazla bilgi için bkz. Hata 203.

  • Geri arama özelliği için parametre ayarları ve kullanım notları hakkında daha fazla bilgi için bkz. Geri Arama.