put() public method

上传二进制流到七牛
public put ( $upToken, $key, $data, $params = null, $mime = 'application/octet-stream', $checkCrc = false ) : array
$upToken 上传凭证
$key 上传文件名
$data 上传二进制流
$params 自定义变量,规格参考 http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#xvar
$mime 上传数据的mimeType
$checkCrc 是否校验crc32
return array 包含已上传文件的信息,类似: [ "hash" => "", "key" => "" ]
Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function write($path, $contents, Config $config)
 {
     list($ret, $error) = $this->uploadManager->put($this->token, $path, $contents);
     if ($error) {
         return false;
     }
     return $ret;
 }
Ejemplo n.º 2
0
 /**
  * 上传图片
  * @param  [type] $imgName [文件名]
  * @param  [type] $content [二进制流]
  * @return [type]          [description]
  */
 public function uploadImage($imgName, $content)
 {
     $token = $this->auth->uploadToken($this->bucket);
     $uploadMgr = new UploadManager();
     list($ret, $err) = $uploadMgr->put($token, $imgName, $content);
     return $this->response($err, $imgName);
 }
Ejemplo n.º 3
0
 public function testData2()
 {
     $upManager = new UploadManager();
     $token = $this->auth->uploadToken($this->bucketName);
     list($ret, $error) = $upManager->put($token, 'formput', 'hello world', null, 'text/plain', true);
     $this->assertNull($error);
     $this->assertNotNull($ret['hash']);
 }
Ejemplo n.º 4
0
 /**
  * 上传数据流到七牛
  * @param $fileName     存储文件名
  * @param $content      内容
  * @return bool
  */
 public function uploadStream($fileName, $content)
 {
     $client = new UploadManager();
     list($ret, $err) = $client->put($this->token, $fileName, $content);
     if ($err != null) {
         return false;
     }
     return $ret;
 }
Ejemplo n.º 5
0
 public function saveImage($tmpFile)
 {
     $upManager = new UploadManager();
     $auth = new Auth($this->config['accessToken'], $this->config['secretToken']);
     $token = $auth->uploadToken($this->config['bucketName']);
     $uploadName = date('Y/m/d/') . Str::lower(Str::quickRandom()) . '.jpg';
     list($ret, $error) = $upManager->put($token, $uploadName, file_get_contents($tmpFile));
     if (!$ret) {
         throw new Exception($error->message());
     }
     return rtrim($this->config['baseUrl'], '/') . '/' . $uploadName;
 }
Ejemplo n.º 6
0
 public function upload($url)
 {
     $data = array();
     $token = $this->auth->uploadToken($this->bucket);
     $uploadMgr = new UploadManager();
     list($ret, $err) = $uploadMgr->put($token, null, file_get_contents($url));
     if ($err !== null) {
         return $data;
     } else {
         $data = array('url' => $this->domain . $ret['key'], 'key' => $ret['key']);
     }
     return $data;
 }
Ejemplo n.º 7
0
 static function upload_content($content, $remote_path)
 {
     if (substr($remote_path, 0, 1) == "/") {
         $remote_path = substr($remote_path, 1);
     }
     $upToken = self::get_uptoken();
     //echo $upToken;exit;
     $uploadMgr = new UploadManager();
     list($ret, $err) = $uploadMgr->put($upToken, $remote_path, $content);
     if ($err !== null) {
         throw new Exception($err->getResponse()->error, $err->getResponse()->statusCode);
     }
     return $ret;
 }
Ejemplo n.º 8
0
 public function uploadQiniu($key, $content)
 {
     $upManager = new UploadManager();
     $auth = new Auth(config('UEditorUpload.core.qiniu.accessKey'), config('UEditorUpload.core.qiniu.secretKey'));
     $token = $auth->uploadToken(config('UEditorUpload.core.qiniu.bucket'));
     list($ret, $error) = $upManager->put($token, $key, $content);
     if ($error) {
         $this->stateInfo = $error->message();
     } else {
         //change $this->fullName ,return the url
         $url = rtrim(strtolower(config('UEditorUpload.core.qiniu.url')), '/');
         $fullName = ltrim($this->fullName, '/');
         $this->fullName = $url . '/' . $fullName;
         $this->stateInfo = $this->stateMap[0];
     }
     return true;
 }
Ejemplo n.º 9
0
<?php

require_once __DIR__ . '/../autoload.php';
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
$accessKey = 'Access_Key';
$secretKey = 'Secret_Key';
$auth = new Auth($accessKey, $secretKey);
$bucket = 'Bucket_Name';
$token = $auth->uploadToken($bucket);
$uploadMgr = new UploadManager();
//----------------------------------------upload demo1 ----------------------------------------
// 上传字符串到七牛
list($ret, $err) = $uploadMgr->put($token, null, 'content string');
echo "\n====> put result: \n";
if ($err !== null) {
    var_dump($err);
} else {
    var_dump($ret);
}
//----------------------------------------upload demo2 ----------------------------------------
// 上传文件到七牛
$filePath = './php-logo.png';
$key = 'php-logo.png';
list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
echo "\n====> putFile result: \n";
if ($err !== null) {
    var_dump($err);
} else {
    var_dump($ret);
}
Ejemplo n.º 10
0
 /**
  * 上传到七牛
  * @param String $key
  * @param UploadedFile $file
  */
 protected function uploadToQiniu($key, $file)
 {
     $uploadConfig = Yii::$app->params['upload'];
     if (isset($uploadConfig['type']) && (trim($uploadConfig['type']) == 'cloud' || trim($uploadConfig['type']) == 'localCloud') && isset($uploadConfig['qiniu']['enabled']) && $uploadConfig['qiniu']['enabled']) {
         //上传
         if (isset($uploadConfig['qiniu']['accessKey']) && isset($uploadConfig['qiniu']['secretKey']) && isset($uploadConfig['qiniu']['bucket'])) {
             $auth = new Auth($uploadConfig['qiniu']['accessKey'], $uploadConfig['qiniu']['secretKey']);
             $token = $auth->uploadToken($uploadConfig['qiniu']['bucket']);
             $upManager = new UploadManager();
             list($ret, $error) = $upManager->put($token, $key, @file_get_contents($file->tempName));
             if ($error !== null) {
                 return false;
             } else {
                 return true;
             }
         }
     }
     return false;
 }
Ejemplo n.º 11
0
 /**
  * 上传字符串
  *
  * @param $string
  * @return mixed
  */
 public function uploadString($string)
 {
     $token = $this->auth->uploadToken($this->bucket, null, 3600, $this->opts);
     $uploadManager = new UploadManager();
     list($result, $error) = $uploadManager->put($token, null, $string);
     if (empty($result)) {
         return $error->getResponse()->error;
     } else {
         return $result;
     }
 }
Ejemplo n.º 12
0
 public function writeWithoutKey($contents, Config $config)
 {
     $uploadManager = new UploadManager();
     $token = $this->getUploadToken();
     return $uploadManager->put($token, null, $contents);
 }