static function Qiniu_PutFile($upToken, $key, $localFile, $putExtra)
 {
     $QINIU_UP_HOST = Conf::$QINIU_UP_HOST;
     if ($putExtra === null) {
         $putExtra = new QiniuPutExtra();
     }
     $fields = array('token' => $upToken, 'file' => QiniuPutExtra::createFile($localFile, $putExtra->MimeType));
     if ($key === null) {
         $fname = '?';
     } else {
         $fname = $key;
         $fields['key'] = $key;
     }
     if ($putExtra->CheckCrc) {
         if ($putExtra->CheckCrc === 1) {
             $hash = hash_file('crc32b', $localFile);
             $array = unpack('N', pack('H*', $hash));
             $putExtra->Crc32 = $array[1];
         }
         $fields['crc32'] = sprintf('%u', $putExtra->Crc32);
     }
     if ($putExtra->Params) {
         foreach ($putExtra->Params as $k => $v) {
             $fields[$k] = $v;
         }
     }
     $client = new QiniuHttpClient();
     return Utils::Qiniu_Client_CallWithForm($client, $QINIU_UP_HOST, $fields, 'multipart/form-data');
 }
Beispiel #2
0
 public function testStat()
 {
     $putPolicy = new QiniuRSPutPolicy($this->bucket . ":" . $this->key);
     $upToken = $putPolicy->Token(null);
     list($ret, $err) = QiniuPutExtra::Qiniu_PutFile($upToken, $this->key, __FILE__, null);
     $this->assertNull($err);
     RSUtils::Qiniu_RS_Delete($this->client, $this->bucket, $this->notExistKey);
     list($ret, $err) = RSUtils::Qiniu_RS_Stat($this->client, $this->bucket, $this->key);
     $this->assertArrayHasKey('hash', $ret);
     $this->assertNull($err);
     list($ret, $err) = RSUtils::Qiniu_RS_Stat($this->client, $this->bucket, $this->notExistKey);
     $this->assertNull($ret);
     $this->assertFalse($err === null);
 }
 public function testPutWithPersistentOps()
 {
     $key = 'testPutWithPersistentOps' . getTid();
     $err = RSUtils::Qiniu_RS_Delete($this->client, $this->bucket, $key);
     $putPolicy = new QiniuRSPutPolicy($this->bucket);
     $putPolicy->PersistentOps = 'avthumb/mp3';
     $putPolicy->PersistentNotifyUrl = 'http://someurl/abc';
     $upToken = $putPolicy->Token(null);
     list($ret, $err) = QiniuPutExtra::Qiniu_Put($upToken, $key, "hello world!", null);
     $this->assertNull($err);
     $this->assertArrayHasKey('hash', $ret);
     $this->assertArrayHasKey('persistentId', $ret);
     var_dump($ret);
     list($ret, $err) = RSUtils::Qiniu_RS_Stat($this->client, $this->bucket, $key);
     $this->assertNull($err);
     var_dump($ret);
     $err = RSUtils::Qiniu_RS_Delete($this->client, $this->bucket, $key);
     $this->assertNull($err);
 }
Beispiel #4
0
 static function Qiniu_RS_PutFile($self, $bucket, $key, $localFile, $putExtra)
 {
     $putPolicy = new QiniuRSPutPolicy("{$bucket}:{$key}");
     $upToken = $putPolicy->Token($self->Mac);
     return QiniuPutExtra::Qiniu_PutFile($upToken, $key, $localFile, $putExtra);
 }
Beispiel #5
0
 public function testPut_mimeLimit()
 {
     $key = 'testPut_mimeLimit' . getTid();
     $scope = $this->bucket . ':' . $key;
     $err = RSUtils::Qiniu_RS_Delete($this->client, $this->bucket, $key);
     $putPolicy = new QiniuRSPutPolicy($scope);
     $putPolicy->MimeLimit = "image/*";
     $upToken = $putPolicy->Token(null);
     list($ret, $err) = QiniuPutExtra::Qiniu_PutFile($upToken, $key, __FILE__, null);
     $this->assertNull($ret);
     $this->assertEquals($err->Err, "limited mimeType: this file type is forbidden to upload");
     var_dump($err);
 }