修改指定资源的存储类型

@param $bucket     待操作资源所在空间
@param $key        待操作资源文件名
@param $fileType       待操作文件目标文件类型

@return mixed      成功返回NULL，失败返回对象Qiniu\Http\Error
@link  https://developer.qiniu.com/kodo/api/3710/modify-the-file-type
775695
public function changeType($bucket, $key, $fileType)
    {
        $resource = \Qiniu\entry($bucket, $key);
        $path = '/chtype/' . $resource . '/type/' . $fileType;
        list(, $error) = $this->rsPost($path);
        return $error;
    }
727026
protected function buildKeysPath($type, $bucket)
    {
        if ($type === null) {
            return sprintf('/buckets/%s/keys', $bucket);
        }

        return sprintf('/types/%s/buckets/%s/keys', $type, $bucket);
    }
949965
public static function files($key=null,$default=null){
    return $key ? (isset($_FILES[$key]) ? $_FILES[$key] : (is_callable($default)?call_user_func($default):$default))  : $_FILES;
  }
1318391
public function delete($bucket, $key)
    {
        $path = '/delete/' . \Qiniu\entry($bucket, $key);
        list(, $error) = $this->rsPost($path);
        return $error;
    }
4226
protected static function getProfile($type, $key = null)
    {
        $type = strtolower($type);

        if (array_key_exists($type, static::$typeDefinitions)) {
            return static::$typeDefinitions[$type][$key];
        }

        if (array_key_exists($type, self::$typeDefinitions)) {
            return self::$typeDefinitions[$type][$key];
        }

        return null;
    }
300006
public function appendFile($bucket, $object, $file, $position, $options = NULL)
    {
        $this->precheckCommon($bucket, $object, $options);

        OssUtil::throwOssExceptionWithMessageIfEmpty($file, "file path is invalid");
        $file = OssUtil::encodePath($file);
        if (!file_exists($file)) {
            throw new OssException($file . " file does not exist");
        }
        $options[self::OSS_FILE_UPLOAD] = $file;
        $file_size = filesize($options[self::OSS_FILE_UPLOAD]);
        $is_check_md5 = $this->isCheckMD5($options);
        if ($is_check_md5) {
            $content_md5 = base64_encode(md5_file($options[self::OSS_FILE_UPLOAD], true));
            $options[self::OSS_CONTENT_MD5] = $content_md5;
        }
        if (!isset($options[self::OSS_CONTENT_TYPE])) {
            $options[self::OSS_CONTENT_TYPE] = $this->getMimeType($object, $file);
        }

        $options[self::OSS_METHOD] = self::OSS_HTTP_POST;
        $options[self::OSS_BUCKET] = $bucket;
        $options[self::OSS_OBJECT] = $object;
        $options[self::OSS_CONTENT_LENGTH] = $file_size;
        $options[self::OSS_SUB_RESOURCE] = 'append';
        $options[self::OSS_POSITION] = strval($position);

        $response = $this->auth($options);
        $result = new AppendResult($response);
        return $result->getData();
    }
285947
public function file($key) {
    if (!isset($this->files[$key])) {
      return null;
    }
    
    return $this->createFile($this->files[$key]);
  }
413287
private function uploadMedia($fileName, $bucket, $key)
    {
        // init multi-part upload
        $initUploadResponse = $this->bosClient->initiateMultipartUpload($bucket, $key);
        $uploadId = $initUploadResponse->uploadId;

        // do upload part
        try {
            $offset = 0;
            $partNumber = 1;
            $partSize = BosClient::MIN_PART_SIZE;
            $length = $partSize;
            $partList = array();
            $bytesLeft = filesize($fileName);

            while ($bytesLeft > 0) {
                $length = ($length > $bytesLeft) ? $bytesLeft : $length;
                $uploadResponse = $this->bosClient->uploadPartFromFile(
                    $bucket,
                    $key,
                    $uploadId,
                    $partNumber,
                    $fileName,
                    $offset,
                    $length);
                array_push($partList, array(
                    'partNumber' => $partNumber,
                    'eTag' => $uploadResponse->metadata['etag'],
                ));
                $offset += $length;
                $partNumber++;
                $bytesLeft -= $length;
            }

            // complete upload
            $this->bosClient->completeMultipartUpload($bucket, $key, $uploadId, $partList);
        } catch (\Exception $e) {
            $this->bosClient->abortMultipartUpload($bucket, $key, $uploadId);
            throw $e;
        }
    }
1208476
public function uploadByUrl($url, $key = null, $bucket = '')
    {
        $filePath = tempnam(sys_get_temp_dir(), 'QN');
        copy($url, $filePath);
        $result = $this->uploadFile($filePath, $key, $bucket);
        unlink($filePath);
        return $result;
    }
1306865
public static Key encodeKey(String bucket, String key) {
    Key res = encodeKeyImpl(bucket, key);
//    assert checkBijection(res, bucket, key);
    return res;
  }
353011
public function batchChangeMime($bucket, $keys, $mime){
        $keyMimePairs = array();
        foreach ($keys as $key) {
            $keyMimePairs[$key] = $mime;
        }
        $ops = $this->bucketManager->buildBatchChangeMime($bucket, $keyMimePairs);
        list($ret, $err) = $this->bucketManager->batch($ops);
        if($err){
            return $this->error($err->message(), ['errorCode'=>$err->code()]);
        }
        return $this->success('操作成功', $ret);
    }
1137827
public function uploadFile($bucket, $object, $file, $options = NULL)
    {
        $this->precheckCommon($bucket, $object, $options);
        OssUtil::throwOssExceptionWithMessageIfEmpty($file, "file path is invalid");
        $file = OssUtil::encodePath($file);
        if (!file_exists($file)) {
            throw new OssException($file . " file does not exist");
        }
        $options[self::OSS_FILE_UPLOAD] = $file;
        $file_size = filesize($options[self::OSS_FILE_UPLOAD]);
        $is_check_md5 = $this->isCheckMD5($options);
        if ($is_check_md5) {
            $content_md5 = base64_encode(md5_file($options[self::OSS_FILE_UPLOAD], true));
            $options[self::OSS_CONTENT_MD5] = $content_md5;
        }
        if (!isset($options[self::OSS_CONTENT_TYPE])) {
            $options[self::OSS_CONTENT_TYPE] = $this->getMimeType($object, $file);
        }
        $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
        $options[self::OSS_BUCKET] = $bucket;
        $options[self::OSS_OBJECT] = $object;
        $options[self::OSS_CONTENT_LENGTH] = $file_size;
        $response = $this->auth($options);
        $result = new PutSetDeleteResult($response);
        return $result->getData();
    }
1084034
public function getStash(?string $key = null)
    {
        $content = json_decode(file_get_contents($this->temp()), true);

        return $key ? (isset($content[$key]) ? $content[$key] : null) : $content;
    }
850765
public function deleteAfterDays($bucket, $key, $days){
        $err = $this->bucketManager->deleteAfterDays($bucket, $key, $days);
        if($err){
            return $this->error($err->message(), ['errorCode'=>$err->code()]);
        }
        return $this->success('操作成功');
    }
463587
public function createBucket($bucket, $region='z0')
    {
        $bucket = \Qiniu\base64_urlSafeEncode($bucket);
        $path = "/mkbucketv2/".$bucket."/region/".$region;
        list(, $error) = $this->rsPost($path);
        return $error;
    }
490470
public function bucket($key = null) {
        if (!$this->id) {
            throw new Exception("The server has no ID, can\'t get buckets");
        }

        $bucket = new Bucket($this->patrol);

        $bucket->defaults([
            'server_id' => $this->id
        ]);

        if (is_null($key)) {
            return $bucket;
        }

        try {
            return $bucket->find($key);
        } catch (Exception $ex) {
            if ($ex->getMessage() === "Bucket does not exist") {
                $bucket->key = $key;
                return $bucket;
            }
        }

        return null;
    }
1038602
public static function files(string $key = null)
    {
        if (!isset($_FILES[$key])) {
            return null;
        }
        if (is_array($_FILES[$key]['name'])) {
            return self::getFileObjects($key);
        } else {
            return new filesystem\UploadedFile($_FILES);
        }
    }