2016-06-13 9 views

Antwort

0

hier ein PHP-Beispiel zum Hochladen von Dateien SoftLayer Object Storage PHP Client mit:

<?php 
require_once ('lib/ObjectStorage/Util.php'); 

class ObjectStorageSL{ 

    var $objectStorage; 
    public function __construct($host, $username, $password, $options) { 

     $this -> objectStorage = new ObjectStorage($host, $username, $password, $options); 

    } 

    /** 
    * This method shows token and url from an object storage 
    * @var $objectStorage - Object Storage connection 
    */ 
    function displayTokenUrl() { 
     print("Token: " . $this -> objectStorage -> getAuthenticationData() -> authToken . "\n"); 
     print("Url: " . $this -> objectStorage -> getAuthenticationData() -> objectStorageUrl); 
    } 

    /** 
    * This method uploads a file located in your local machine 
    * @var $objectStorage - Object Storage connection 
    * @var $containerName - The container's name where you want to upload the object 
    * @var $objectName - The object's name that you wish to assign for the file uploaded 
    * @var $path - The path where the file is located 
    */ 
    function uploadFile($containerName, $objectName, $path) { 
     try { 
      $result = $this -> objectStorage -> with($containerName . "/" . $objectName) -> setLocalFile($path) -> create(); 
      print("\n".$result -> getUrl()); 
      print("\nThe file has been uploaded"); 
     } catch(Exception $e) { 
      echo "\nError: " . $e -> getMessage(); 
     } 
    } 
} 


/** 
* Declare Object Storage parameters 
*/ 
$host = 'https://mil01.objectstorage.softlayer.net/auth/v1.0/'; 
// Declare your username and password for Object Storage connection 
$username = 'set me'; 
$password = 'set me'; 
$options = array('adapter' => ObjectStorage_Http_Client::SOCKET, 'timeout' => 10); 

/** 
* Create Object Storage Connection 
*/ 
$objectStorage = new ObjectStorageSL($host, $username, $password, $options); 

/** 
* Display Token and Url 
*/ 
$objectStorage -> displayTokenUrl(); 
$path = "C:\Project\task.xml"; 
$objectStorage -> uploadFile("rcvTest", "task1.xml", $path); 

teste ich habe es nicht mit Dateien größer als 10 MB, aber es sollte funktionieren, lassen Sie mich wissen, wenn Sie Probleme oder Fragen haben

+0

Ich benutze diesen Ansatz jetzt und das ist nicht 100%, die ich brauche. z. Ich habe Datei mit der Größe von 50mb. Kann ich ihn in 5 Teile teilen und sie einzeln hochladen und in den Softlayer-Server zusammenfassen? (Die erste Anfrage wird eine Datei erstellen, andere Anfragen werden Daten an die Datei anhängen oder so) –

+0

Leider habe ich für große Dateien keine Methode im Client gesehen, um sie zu teilen. Wie auch immer, werfen Sie einen Blick auf diese Informationen, wahrscheinlich wird es Ihnen helfen: http://docs.openstack.org/developer/swift/api/large_objects.html –