• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (PHP SDK)
  4. Object Upload
  5. Performing a Streaming Upload

Performing a Streaming Upload

Streaming upload uses resource or GuzzleHttp\Psr7\Stream as the data source of an object. Sample code is as follows:

Uploading a Network Stream

// Import the third-party open source libraries.
require 'vendor/autoload.php';
// Import the SDK code library.
require 'obs-autoloader.php';
// Declare the namespace.
use Obs\S3\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient([
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',
       'endpoint' => 'https://yourdomainname'
]);

$resp = $obsClient->putObject([
       'Bucket' => 'bucketname',
       'Key' => 'objectkey',
       // Create network streams.
       'Body' => fopen('http://www.a.com','r')
]);

printf("RequestId:%s\n",$resp['RequestId']);

Uploading a File Stream

// Import the third-party open source libraries.
require 'vendor/autoload.php';
// Import the SDK code library.
require 'obs-autoloader.php';
// Declare the namespace.
use Obs\S3\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient([
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',
       'endpoint' => 'https://yourdomainname'
]);

$resp = $obsClient->putObject([
       'Bucket' => 'bucketname',
       'Key' => 'objectkey',
       'Body' => fopen('localfile', 'r')
]);

printf("RequestId:%s\n",$resp['RequestId']);
  • If the Body parameter is used to specify the to-be-uploaded streaming data, its value must be a resource object or an instance of GuzzleHttp\Psr7\Stream.
  • To upload a large file, you are advised to use multipart upload.