Tüm Ürünler
Search
Belge Merkezi

Object Storage Service:Append upload (PHP SDK V1)

Son Güncelleme:Oct 13, 2026

Mevcut eklenebilir nesnelere içerik eklemek için AppendObject işlemini çağırabilirsiniz.

Kullanım notları

  • Bu konuda Çin (Hangzhou) bölgesinin genel uç noktası kullanılmaktadır. Aynı bölgedeki diğer Alibaba Cloud hizmetlerinden OSS'e erişmek için dahili uç noktayı kullanın. Desteklenen bölgeler ve uç noktalar hakkında daha fazla bilgi için Bölgeler ve uç noktalar konusuna bakın.

  • Bu konuda erişim kimlik bilgileri ortam değişkenlerinden alınır. Daha fazla bilgi için Erişim kimlik bilgilerini yapılandırma konusuna bakın.

  • Bu konu, bir OSS uç noktası kullanarak bir OSSClient örneğinin nasıl oluşturulacağını gösterir. Özel alan adı kullanma veya Security Token Service (STS) kimlik bilgileriyle kimlik doğrulama gibi alternatif yapılandırmalar için İstemci yapılandırması konusuna bakın.

  • İçerik eklemek istediğiniz nesne mevcut değilse AppendObject işlemi eklenebilir bir nesne oluşturur.

  • İçerik eklemek istediğiniz nesne mevcutsa:

    • Nesne eklenebilir bir nesneyse ve ekleme işleminin başlayacağı belirtilen konum mevcut nesne boyutuna eşitse veriler nesnenin sonuna eklenir.

    • Nesne eklenebilir bir nesneyse ve ekleme işleminin başlayacağı belirtilen konum mevcut nesne boyutuna eşit değilse PositionNotEqualToLength hatası döndürülür.

    • Nesne eklenebilir bir nesne değilse ObjectNotAppendable hatası döndürülür.

İzinler

Varsayılan olarak bir Alibaba Cloud hesabı tüm izinlere sahiptir. Bir Alibaba Cloud hesabı altındaki RAM kullanıcıları veya RAM rollerinde varsayılan olarak herhangi bir izin bulunmaz. Alibaba Cloud hesabı veya hesap yöneticisi, RAM ilkeleri veya Bucket Policy aracılığıyla işlem izinleri vermelidir.

API

Action

Description

AppendObject

oss:PutObject

Bu işlemi, mevcut bir nesneye ekleyerek bir nesne yüklemek için çağırabilirsiniz.

oss:PutObjectTagging

Mevcut bir nesneye ekleyerek nesne yüklerken x-oss-tagging aracılığıyla nesne etiketleri belirtirseniz bu iznin olması gerekir.

Dize ekleme

Aşağıdaki kod, examplebucket paketindeki srcexampleobject.txt dosyasına dizelerin sırayla nasıl ekleneceğini gösterir.

<?php
if (is_file(__DIR__ . '/../autoload.php')) {
    require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}

use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
use OSS\CoreOssException;

// Obtain access credentials from environment variables. Before you run this example, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
$provider = new EnvironmentVariableCredentialsProvider();
// The China (Hangzhou) endpoint is used as an example. Set the endpoint to the actual endpoint. For more information about the mapping between regions and endpoints, see Endpoints.
$endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the bucket name. For more information about bucket naming conventions, see Buckets.
$bucket= "examplebucket";
// Specify the full path of the object. Do not include the bucket name. For more information about object naming conventions, see Terms.
$object = "srcexampleobject.txt";
// Specify the strings to append in sequence. After the first, second, and third append operations, the file content is "Hello OSS", "Hi OSS", and "OSS OK", respectively.
$content_array = array('Hello OSS', 'Hi OSS', 'OSS OK');

$options = array(
    'headers' => array(
        // Specify the web page caching behavior when the object is downloaded.
        // 'Cache-Control' => 'no-cache',
        // Specify the name of the object when it is downloaded.
        // 'Content-Disposition' => 'attachment;filename=oss_download.jpg',
        // Specify the expiration time.
        // 'Expires' => 'Fri, 31 Dec 2021 16:57:01 GMT',
        // Specify whether to overwrite an object that has the same name during an append upload. Set this parameter to true to prohibit overwriting.
        // 'x-oss-forbid-overwrite' => 'true',
        // Specify the server-side encryption method for each part of the object.
        // 'x-oss-server-side-encryption'=> 'AES256',
        // Specify the encryption algorithm for the object.
        // 'x-oss-server-side-data-encryption'=>'SM4',
        // Specify the storage class of the object.
        // 'x-oss-storage-class' => 'Standard',
        // Specify the access permissions for the object.
        // 'x-oss-object-acl' => 'private',
        ),
);

try{
    $config = array(
        "provider" => $provider,
        "endpoint" => $endpoint,
        "signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
        "region"=> "cn-hangzhou"
    );
    $ossClient = new OssClient($config);

    // Perform the first append upload. The position for the first append is 0. The return value indicates the position for the next append. The position for subsequent appends is the length of the file before the append.
    $position = $ossClient->appendObject($bucket, $object, $content_array[0], 0,$options);
    $position = $ossClient->appendObject($bucket, $object, $content_array[1], $position,$options);
    $position = $ossClient->appendObject($bucket, $object, $content_array[2], $position,$options);
} catch(OssException $e) {
    printf(__FUNCTION__ . ": FAILED\n");
    printf($e->getMessage() . "\n");
    return;
}
print(__FUNCTION__ . ": OK" . "\n");           

Yerel dosya ekleme

Aşağıdaki kod, examplefilea.txt, examplefileb.txt ve examplefilec.txt yerel dosyalarının içeriğinin examplebucket paketindeki exampleobject.txt dosyasına sırayla nasıl ekleneceğini gösterir.

 <?php
if (is_file(__DIR__ . '/../autoload.php')) {
    require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
    require_once __DIR__ . '/../vendor/autoload.php';
}

use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
use OSS\CoreOssException;

// Obtain access credentials from environment variables. Before you run this example, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
$provider = new EnvironmentVariableCredentialsProvider();
// The China (Hangzhou) endpoint is used as an example. Set the endpoint to the actual endpoint.
$endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the bucket name.
$bucket= "examplebucket";
// Specify the full path of the object. Do not include the bucket name.
$object = "exampleobject.txt";
// Specify the full path of the local file. If you do not specify a local path, the file is uploaded from the project path of the sample program by default.
$filePath = "D:\\localpath\\examplefilea.txt";
$filePath1 = "D:\\localpath\\examplefileb.txt";
$filePath2 = "D:\\localpath\\examplefilec.txt";

try{
    $config = array(
        "provider" => $provider,
        "endpoint" => $endpoint,
        "signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
        "region"=> "cn-hangzhou"
    );
    $ossClient = new OssClient($config);
    // Perform the first append upload. The position for the first append is 0. The return value indicates the position for the next append. The position for subsequent appends is the length of the file before the append.
    $position = $ossClient->appendFile($bucket, $object, $filePath, 0);
    $position = $ossClient->appendFile($bucket, $object, $filePath1, $position);
    $position = $ossClient->appendFile($bucket, $object, $filePath2, $position);
} catch(OssException $e) {
    printf(__FUNCTION__ . ": FAILED\n");
    printf($e->getMessage() . "\n");
    return;
}
print(__FUNCTION__ . ": OK" . "\n");            

İlgili bilgiler

Ekleme yöntemiyle yükleme için kullanılan API işlemi hakkında daha fazla bilgi için AppendObject konusuna bakın.