Exemplo n.º 1
0
 private function putFileInDirectory($directory, $localFile, $destinationName)
 {
     $createDirectory = false;
     // TODO confirm is this is the best way to do this
     //  it maybe a noop but calling get_file_info might be faster
     try {
         $newFolder = new Box_Client_Folder();
         $newFolder->attr('name', $directory);
         $newFolder->attr('parent_id', $this->boxFolderId);
         $newFolder->attr('share', 0);
         $status = $this->box->create($newFolder);
         if ($status !== self::statusCreatedOk && $status !== self::statusFolderExists) {
             getLogger()->warn(sprintf('Box API returned an unexpected response of (%s) from folder create call', $status));
             return false;
         }
     } catch (Box_Rest_Client_Exception $e) {
         getLogger()->warn('Box exception from folder create call', $e);
         return false;
     }
     try {
         // The way Box_Rest_Client works it uses the file's name as the display name
         $file = new Box_Client_File($localFile, $destinationName);
         $file->attr('folder_id', $newFolder->attr('folder_id'));
         $result = $this->box->upload($file, array('new_copy' => '1'), true);
         if ($result === self::statusUploadOk) {
             $this->metaDataMap[$localFile] = array('boxFileId' => $file->attr('id'));
             getLogger()->info(sprintf('Successfully stored file (%s) on Box.', $destinationName));
             return true;
         } else {
             getLogger()->crit('Could not put file on Box.', $e);
             return false;
         }
     } catch (Box_Rest_Client_Exception $e) {
         getLogger()->warn('Box exception from upload call', $e);
         return false;
     }
 }
Exemplo n.º 2
0
 /**
  * 
  * Creates a folder on the server with the specified attributes.
  * @param Box_Client_Folder $folder
  */
 public function create(Box_Client_Folder &$folder)
 {
     $params = array('name' => $folder->attr('name'), 'parent_id' => intval($folder->attr('parent_id')), 'share' => intval($folder->attr('share')));
     $res = $this->post('create_folder', $params);
     if ($res['status'] == 'create_ok' || $res['status'] == 's_folder_exists') {
         foreach ($res['folder'] as $key => $val) {
             $folder->attr($key, $val);
         }
     }
     return $res['status'];
 }