@@ -12,7 +12,7 @@ |
||
| 12 | 12 | { |
| 13 | 13 | public function boot() |
| 14 | 14 | { |
| 15 | - app('filesystem')->extend('wantu', function ($app, $config) { |
|
| 15 | + app('filesystem')->extend('wantu', function($app, $config) { |
|
| 16 | 16 | $adapter = new WantuFileAdapter( |
| 17 | 17 | $config['access_key'], |
| 18 | 18 | $config['secret_key'], |
@@ -355,7 +355,7 @@ |
||
| 355 | 355 | return $this->client->getUploadToken(collect([ |
| 356 | 356 | 'expiration' => Carbon::now()->addSeconds($option['ttl'])->timestamp * 1000, |
| 357 | 357 | 'insertOnly' => Conf::INSERT_ONLY_TRUE |
| 358 | - ])->merge(collect($option)->except(['ttl',]))); |
|
| 358 | + ])->merge(collect($option)->except(['ttl', ]))); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | private $namespace; |
| 20 | 20 | private $type; // "TOP"和"CLOUD"两种模式 |
| 21 | 21 | |
| 22 | - static $RUN_LEVEL = Conf::RUN_LEVEL_RELEASE; //设置SDK运行级别 |
|
| 22 | + static $RUN_LEVEL = Conf::RUN_LEVEL_RELEASE; //设置SDK运行级别 |
|
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * 构造函数 |
@@ -38,10 +38,10 @@ discard block |
||
| 38 | 38 | return $this->_errorResponse("FileNotExist", "file not exist"); |
| 39 | 39 | } |
| 40 | 40 | if (empty($uploadOption)) { |
| 41 | - $uploadOption = new UploadOption(); //如果用户没有传递UploadOption,则生成一个默认的 |
|
| 41 | + $uploadOption = new UploadOption(); //如果用户没有传递UploadOption,则生成一个默认的 |
|
| 42 | 42 | } |
| 43 | 43 | if (empty($uploadOption->name)) { |
| 44 | - $uploadOption->name = basename($filePath); //如果用户没有设置name属性,则使用上传时的文件名 |
|
| 44 | + $uploadOption->name = basename($filePath); //如果用户没有设置name属性,则使用上传时的文件名 |
|
| 45 | 45 | } |
| 46 | 46 | // UploadPolicy 和 UploadOption检查 |
| 47 | 47 | list($isValid, $message) = $this->checkUploadInfo($uploadPolicy, $uploadOption); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | { |
| 69 | 69 | $data = file_get_contents($filePath); |
| 70 | 70 | $uploadOption->setContent($data); |
| 71 | - $url = $this->upload_host . Conf::UPLOAD_API_UPLOAD; //普通上传的API |
|
| 71 | + $url = $this->upload_host . Conf::UPLOAD_API_UPLOAD; //普通上传的API |
|
| 72 | 72 | return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); |
| 73 | 73 | } |
| 74 | 74 | |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | protected function uploadSuperFile($filePath, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null) |
| 83 | 83 | { |
| 84 | - $fileSize = filesize($filePath); // 文件大小 |
|
| 85 | - $blockSize = $uploadOption->blockSize; // 文件分片大小 |
|
| 84 | + $fileSize = filesize($filePath); // 文件大小 |
|
| 85 | + $blockSize = $uploadOption->blockSize; // 文件分片大小 |
|
| 86 | 86 | $blockNum = intval(ceil($fileSize / $blockSize)); // 文件分片后的块数 |
| 87 | 87 | for ($i = 0; $i < $blockNum; $i++) { |
| 88 | 88 | $currentSize = $blockSize; // 当前文件块的大小 |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | $httpRes = null; |
| 96 | 96 | if (0 == $i) { |
| 97 | 97 | // 分片初始化阶段 |
| 98 | - $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT; //初始化分片上传的API |
|
| 99 | - $uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD; //初始化分片时的Option类型 |
|
| 98 | + $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT; //初始化分片上传的API |
|
| 99 | + $uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD; //初始化分片时的Option类型 |
|
| 100 | 100 | $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); |
| 101 | 101 | $uploadId = isset($httpRes['uploadId']) ? $httpRes['uploadId'] : null; // 分片上传ID(OSS用于区分上传的id) |
| 102 | 102 | $id = isset($httpRes['id']) ? $httpRes['id'] : null; // 上传唯一ID(多媒体服务用于区分上传的id) |
@@ -104,16 +104,16 @@ discard block |
||
| 104 | 104 | $uploadOption->setUniqueIdId($id); |
| 105 | 105 | } else { |
| 106 | 106 | // 分片上传过程中 |
| 107 | - $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD; //分片上传过程中的API |
|
| 108 | - $uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD; //分片上传过程中的Option类型 |
|
| 109 | - $uploadOption->setPartNumber($i + 1); // |
|
| 107 | + $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD; //分片上传过程中的API |
|
| 108 | + $uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD; //分片上传过程中的Option类型 |
|
| 109 | + $uploadOption->setPartNumber($i + 1); // |
|
| 110 | 110 | $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); |
| 111 | 111 | } |
| 112 | 112 | // 如果分片上传失败,则取消cancel分片上传任务,然后返回错误信息 |
| 113 | 113 | if (!$httpRes['isSuccess']) { |
| 114 | 114 | if ($uploadOption->checkMutipartParas()) { |
| 115 | - $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL; //取消分片任务的API |
|
| 116 | - $uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD; //取消分片任务时的Option类型 |
|
| 115 | + $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL; //取消分片任务的API |
|
| 116 | + $uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD; //取消分片任务时的Option类型 |
|
| 117 | 117 | $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); // 不判断取消分片任务返回的结果 |
| 118 | 118 | } |
| 119 | 119 | return $httpRes; |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | $uploadOption->addPartNumberAndETag($httpRes['partNumber'], $httpRes['eTag']); |
| 127 | 127 | } |
| 128 | 128 | // 分片上传完成 |
| 129 | - $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE; //完成分片上传任务的API |
|
| 130 | - $uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD; //完成分片上传任务时的Option类型 |
|
| 131 | - $uploadOption->setMd5(md5_file($filePath)); //文件Md5 |
|
| 129 | + $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE; //完成分片上传任务的API |
|
| 130 | + $uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD; //完成分片上传任务时的Option类型 |
|
| 131 | + $uploadOption->setMd5(md5_file($filePath)); //文件Md5 |
|
| 132 | 132 | return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); |
| 133 | 133 | } |
| 134 | 134 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | public function uploadData($data, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null) |
| 145 | 145 | { |
| 146 | 146 | if (empty($uploadOption)) { |
| 147 | - $uploadOption = new UploadOption(); //如果用户没有传递UploadOption,则生成一个默认的 |
|
| 147 | + $uploadOption = new UploadOption(); //如果用户没有传递UploadOption,则生成一个默认的 |
|
| 148 | 148 | } |
| 149 | 149 | // UploadPolicy 和 UploadOption检查 |
| 150 | 150 | list($isValid, $message) = $this->checkUploadInfo($uploadPolicy, $uploadOption); |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | // 文件不大于设定的分片大小(默认2M),则直接上传uploadMiniFile() |
| 160 | 160 | $uploadOption->setContent($data); |
| 161 | - $url = $this->upload_host . Conf::UPLOAD_API_UPLOAD; //普通上传的API |
|
| 161 | + $url = $this->upload_host . Conf::UPLOAD_API_UPLOAD; //普通上传的API |
|
| 162 | 162 | return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); |
| 163 | 163 | } |
| 164 | 164 | |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | */ |
| 172 | 172 | protected function uploadSuperData($data, UploadPolicy $uploadPolicy, UploadOption $uploadOption = null) |
| 173 | 173 | { |
| 174 | - $dataSize = strlen($data); // 文件大小 |
|
| 175 | - $blockSize = $uploadOption->blockSize; // 文件分片大小 |
|
| 174 | + $dataSize = strlen($data); // 文件大小 |
|
| 175 | + $blockSize = $uploadOption->blockSize; // 文件分片大小 |
|
| 176 | 176 | $blockNum = intval(ceil($dataSize / $blockSize)); // 文件分片后的块数 |
| 177 | 177 | for ($i = 0; $i < $blockNum; $i++) { |
| 178 | 178 | $currentSize = $blockSize; // 当前文件块的大小 |
@@ -185,8 +185,8 @@ discard block |
||
| 185 | 185 | $httpRes = null; |
| 186 | 186 | if (0 == $i) { |
| 187 | 187 | // 分片初始化阶段 |
| 188 | - $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT; //初始化分片上传的API |
|
| 189 | - $uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD; //初始化分片时的Option类型 |
|
| 188 | + $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT; //初始化分片上传的API |
|
| 189 | + $uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD; //初始化分片时的Option类型 |
|
| 190 | 190 | $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); |
| 191 | 191 | $uploadId = isset($httpRes['uploadId']) ? $httpRes['uploadId'] : null; // 分片上传ID(OSS用于区分上传的id) |
| 192 | 192 | $id = isset($httpRes['id']) ? $httpRes['id'] : null; // 上传唯一ID(多媒体服务用于区分上传的id) |
@@ -194,16 +194,16 @@ discard block |
||
| 194 | 194 | $uploadOption->setUniqueIdId($id); |
| 195 | 195 | } else { |
| 196 | 196 | // 分片上传过程中 |
| 197 | - $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD; //分片上传过程中的API |
|
| 198 | - $uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD; //分片上传过程中的Option类型 |
|
| 199 | - $uploadOption->setPartNumber($i + 1); // |
|
| 197 | + $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD; //分片上传过程中的API |
|
| 198 | + $uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD; //分片上传过程中的Option类型 |
|
| 199 | + $uploadOption->setPartNumber($i + 1); // |
|
| 200 | 200 | $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); |
| 201 | 201 | } |
| 202 | 202 | // 如果分片上传失败,则取消cancel分片上传任务,然后返回错误信息 |
| 203 | 203 | if (!$httpRes['isSuccess']) { |
| 204 | 204 | if ($uploadOption->checkMutipartParas()) { |
| 205 | - $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL; //取消分片任务的API |
|
| 206 | - $uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD; //取消分片任务时的Option类型 |
|
| 205 | + $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL; //取消分片任务的API |
|
| 206 | + $uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD; //取消分片任务时的Option类型 |
|
| 207 | 207 | $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); // 不判断取消分片任务返回的结果 |
| 208 | 208 | } |
| 209 | 209 | return $httpRes; |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | $uploadOption->addPartNumberAndETag($httpRes['partNumber'], $httpRes['eTag']); |
| 213 | 213 | } |
| 214 | 214 | // 分片上传完成 |
| 215 | - $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE; //完成分片上传任务的API |
|
| 216 | - $uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD; //完成分片上传任务时的Option类型 |
|
| 217 | - $uploadOption->setMd5(md5($data)); //文件Md5 |
|
| 215 | + $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE; //完成分片上传任务的API |
|
| 216 | + $uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD; //完成分片上传任务时的Option类型 |
|
| 217 | + $uploadOption->setMd5(md5($data)); //文件Md5 |
|
| 218 | 218 | return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); |
| 219 | 219 | } |
| 220 | 220 | |
@@ -232,10 +232,10 @@ discard block |
||
| 232 | 232 | return $this->_errorResponse("FileNotExist", "file not exist"); |
| 233 | 233 | } |
| 234 | 234 | if (empty($uploadOption)) { |
| 235 | - $uploadOption = new UploadOption(); //如果用户没有传递UploadOption,则生成一个默认的 |
|
| 235 | + $uploadOption = new UploadOption(); //如果用户没有传递UploadOption,则生成一个默认的 |
|
| 236 | 236 | } |
| 237 | 237 | if (empty($uploadOption->name)) { |
| 238 | - $uploadOption->name = basename($filePath); //如果用户没有设置name属性,则使用上传时的文件名 |
|
| 238 | + $uploadOption->name = basename($filePath); //如果用户没有设置name属性,则使用上传时的文件名 |
|
| 239 | 239 | } |
| 240 | 240 | $blockData = file_get_contents($encodePath, 0, null, 0, $uploadOption->blockSize); |
| 241 | 241 | return $this->multipartInitByData($blockData, $uploadPolicy, $uploadOption); |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | public function multipartInitByData($blockData, UploadPolicy $uploadPolicy, UploadOption $uploadOption) |
| 252 | 252 | { |
| 253 | 253 | if (empty($uploadOption)) { |
| 254 | - $uploadOption = new UploadOption(); //如果用户没有传递UploadOption,则生成一个默认的 |
|
| 254 | + $uploadOption = new UploadOption(); //如果用户没有传递UploadOption,则生成一个默认的 |
|
| 255 | 255 | } |
| 256 | 256 | // UploadPolicy 和 UploadOption检查 |
| 257 | 257 | list($isValid, $message) = $this->checkUploadInfo($uploadPolicy, $uploadOption); |
@@ -259,13 +259,13 @@ discard block |
||
| 259 | 259 | return $this->_errorResponse("ErrorUploadInfo", "error upload policy or option:" . $message); |
| 260 | 260 | } |
| 261 | 261 | // 数据大小不等于设定的分片大小(默认2M),则无法完成初始化 |
| 262 | - $dataSize = strlen($blockData); // 数据文件大小 |
|
| 262 | + $dataSize = strlen($blockData); // 数据文件大小 |
|
| 263 | 263 | if ($dataSize != ($uploadOption->blockSize)) { |
| 264 | 264 | return $this->_errorResponse("MultipartInitError", "UploadOption's blockSize is not equal to data's size"); |
| 265 | 265 | } |
| 266 | 266 | $uploadOption->setContent($blockData); // 设置待上传的文件块 |
| 267 | - $uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD; //初始化分片时的Option类型 |
|
| 268 | - $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT; //初始化分片上传的API |
|
| 267 | + $uploadOption->optionType = UpOptionType::BLOCK_INIT_UPLOAD; //初始化分片时的Option类型 |
|
| 268 | + $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_INIT; //初始化分片上传的API |
|
| 269 | 269 | $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); |
| 270 | 270 | //若成功返回,则保存初始化成功的uploadId、id 以及 partNumber、eTag |
| 271 | 271 | $uploadId = isset($httpRes['uploadId']) ? $httpRes['uploadId'] : null; // 分片上传ID(OSS用于区分上传的id) |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | if (!file_exists($encodePath)) { |
| 291 | 291 | return $this->_errorResponse("FileNotExist", "file not exist"); |
| 292 | 292 | } |
| 293 | - $fileSize = filesize($encodePath); // 文件大小 |
|
| 294 | - $blockSize = $uploadOption->blockSize; // 文件分片大小 |
|
| 293 | + $fileSize = filesize($encodePath); // 文件大小 |
|
| 294 | + $blockSize = $uploadOption->blockSize; // 文件分片大小 |
|
| 295 | 295 | $blockNum = intval(ceil($fileSize / $blockSize)); // 文件分片后的块数 |
| 296 | 296 | $currentSize = $blockSize; // 当前文件块的大小 |
| 297 | 297 | if ($uploadOption->getPartNumber() == $blockNum) { |
@@ -317,8 +317,8 @@ discard block |
||
| 317 | 317 | return $this->_errorResponse("MultipartUploadError", "multipart upload's parameters(id,uploadId,partNumber) error"); |
| 318 | 318 | } |
| 319 | 319 | $uploadOption->setContent($blockData); // 设置待上传的文件块 |
| 320 | - $uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD; //分片上传过程中的Option类型 |
|
| 321 | - $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD; //分片上传过程中的API |
|
| 320 | + $uploadOption->optionType = UpOptionType::BLOCK_RUN_UPLOAD; //分片上传过程中的Option类型 |
|
| 321 | + $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_UPLOAD; //分片上传过程中的API |
|
| 322 | 322 | $httpRes = $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); |
| 323 | 323 | if (isset($httpRes['partNumber']) && isset($httpRes['eTag'])) { |
| 324 | 324 | $uploadOption->addPartNumberAndETag($httpRes['partNumber'], $httpRes['eTag']); |
@@ -339,8 +339,8 @@ discard block |
||
| 339 | 339 | if (!$uploadOption->checkMutipartParas() || empty($fileMd5)) { |
| 340 | 340 | return $this->_errorResponse("MultipartCompleteError", "multipart upload's parameters(id,uploadId,md5) error"); |
| 341 | 341 | } |
| 342 | - $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE; //完成分片上传任务的API |
|
| 343 | - $uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD; //完成分片上传任务时的Option类型 |
|
| 342 | + $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_COMPLETE; //完成分片上传任务的API |
|
| 343 | + $uploadOption->optionType = UpOptionType::BLOCK_COMPLETE_UPLOAD; //完成分片上传任务时的Option类型 |
|
| 344 | 344 | return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); |
| 345 | 345 | } |
| 346 | 346 | |
@@ -355,8 +355,8 @@ discard block |
||
| 355 | 355 | if (!$uploadOption->checkMutipartParas()) { |
| 356 | 356 | return $this->_errorResponse("MultipartCancelError", "multipart upload's parameters(id,uploadId) error"); |
| 357 | 357 | } |
| 358 | - $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL; //取消分片任务的API |
|
| 359 | - $uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD; //取消分片任务时的Option类型 |
|
| 358 | + $url = $this->upload_host . Conf::UPLOAD_API_BLOCK_CANCEL; //取消分片任务的API |
|
| 359 | + $uploadOption->optionType = UpOptionType::BLOCK_CANCEL_UPLOAD; //取消分片任务时的Option类型 |
|
| 360 | 360 | return $this->_send_request('POST', $url, $uploadPolicy, $uploadOption); |
| 361 | 361 | } |
| 362 | 362 | |
@@ -384,17 +384,17 @@ discard block |
||
| 384 | 384 | list($contentType, $httpBody) = $this->BuildMultipartForm($uploadOption); |
| 385 | 385 | $length = @strlen($httpBody); |
| 386 | 386 | array_push($_headers, "Content-Type: {$contentType}"); |
| 387 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $httpBody); //请求体 |
|
| 387 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $httpBody); //请求体 |
|
| 388 | 388 | } |
| 389 | 389 | array_push($_headers, "Content-Length: {$length}"); |
| 390 | - curl_setopt($ch, CURLOPT_HEADER, 1); //设置头部 |
|
| 391 | - curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers); //请求头 |
|
| 392 | - curl_setopt($ch, CURLOPT_TIMEOUT, $uploadOption->timeout); //持续时长 |
|
| 393 | - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); //连接超时时长 |
|
| 390 | + curl_setopt($ch, CURLOPT_HEADER, 1); //设置头部 |
|
| 391 | + curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers); //请求头 |
|
| 392 | + curl_setopt($ch, CURLOPT_TIMEOUT, $uploadOption->timeout); //持续时长 |
|
| 393 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); //连接超时时长 |
|
| 394 | 394 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //成功,只返回结果,不自动输出任何内容。如果失败返回FALSE |
| 395 | 395 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); |
| 396 | 396 | curl_setopt($ch, CURLOPT_URL, $url); |
| 397 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //自定义请求 |
|
| 397 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //自定义请求 |
|
| 398 | 398 | //设置请求方式(GET或POST等) |
| 399 | 399 | if ($method == 'PUT' || $method == 'POST') { |
| 400 | 400 | curl_setopt($ch, CURLOPT_POST, 1); |
@@ -415,10 +415,10 @@ discard block |
||
| 415 | 415 | } else { |
| 416 | 416 | //解析返回结果,并判断是否上传成功 |
| 417 | 417 | $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 418 | - $success = ($http_code == 200) ? true : false; //判断是否上传成功 |
|
| 418 | + $success = ($http_code == 200) ? true : false; //判断是否上传成功 |
|
| 419 | 419 | $resStr = explode("\r\n\r\n", $response); |
| 420 | 420 | $resBody = isset($resStr[1]) ? $resStr[1] : ''; |
| 421 | - $resArray = json_decode($resBody, true); //解析得到结果 |
|
| 421 | + $resArray = json_decode($resBody, true); //解析得到结果 |
|
| 422 | 422 | $result = (empty($resArray) ? $result : $resArray); |
| 423 | 423 | } |
| 424 | 424 | } catch (Exception $e) { |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | $_headers = array('Expect:'); |
| 336 | 336 | $date = $this->currentMilliSecond(); //得到当前的时间戳,毫秒 |
| 337 | 337 | array_push($_headers, "Date: {$date}"); |
| 338 | - $authorization = $this->_getAuthorization($uri, $date, $httpBody); //Http的Body需要加入管理鉴权 |
|
| 338 | + $authorization = $this->_getAuthorization($uri, $date, $httpBody); //Http的Body需要加入管理鉴权 |
|
| 339 | 339 | array_push($_headers, "Authorization: {$authorization}"); |
| 340 | 340 | array_push($_headers, "User-Agent: {$this->_getUserAgent()}"); |
| 341 | 341 | if (!is_null($headers) && is_array($headers)) { |
@@ -354,13 +354,13 @@ discard block |
||
| 354 | 354 | array_push($_headers, "Content-Type: application/x-www-form-urlencoded"); |
| 355 | 355 | } |
| 356 | 356 | array_push($_headers, "Content-Length: {$length}"); |
| 357 | - curl_setopt($ch, CURLOPT_HEADER, 1); //设置头部 |
|
| 358 | - curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers); //请求头 |
|
| 359 | - curl_setopt($ch, CURLOPT_TIMEOUT, Conf::HTTP_TIMEOUT); //超时时长 |
|
| 360 | - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); //连接超时时长 |
|
| 357 | + curl_setopt($ch, CURLOPT_HEADER, 1); //设置头部 |
|
| 358 | + curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers); //请求头 |
|
| 359 | + curl_setopt($ch, CURLOPT_TIMEOUT, Conf::HTTP_TIMEOUT); //超时时长 |
|
| 360 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); //连接超时时长 |
|
| 361 | 361 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //成功,只返回结果,不自动输出任何内容。如果失败返回FALSE |
| 362 | 362 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); |
| 363 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //自定义请求 |
|
| 363 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); //自定义请求 |
|
| 364 | 364 | //设置请求方式(GET或POST等) |
| 365 | 365 | if ($method == 'PUT' || $method == 'POST') { |
| 366 | 366 | curl_setopt($ch, CURLOPT_POST, 1); |
@@ -375,10 +375,10 @@ discard block |
||
| 375 | 375 | } else { |
| 376 | 376 | //解析返回结果,并判断是否上传成功 |
| 377 | 377 | $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 378 | - $success = ($http_code == 200) ? true : false; //判断是否上传成功 |
|
| 378 | + $success = ($http_code == 200) ? true : false; //判断是否上传成功 |
|
| 379 | 379 | $resStr = explode("\r\n\r\n", $response); |
| 380 | 380 | $resBody = isset($resStr[1]) ? $resStr[1] : ''; |
| 381 | - $resArray = json_decode($resBody, true); //解析得到结果 |
|
| 381 | + $resArray = json_decode($resBody, true); //解析得到结果 |
|
| 382 | 382 | $result = (empty($resArray)) ? array() : $resArray; |
| 383 | 383 | } |
| 384 | 384 | } catch (Exception $e) { |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | protected function currentMilliSecond() |
| 451 | 451 | { |
| 452 | 452 | list($microSec, $stampSec) = explode(' ', microtime()); |
| 453 | - $tempMilli = sprintf('%03s', intval($microSec * 1000)); |
|
| 453 | + $tempMilli = sprintf('%03s', intval($microSec * 1000)); |
|
| 454 | 454 | $currentMilli = $stampSec . $tempMilli; |
| 455 | 455 | return $currentMilli; |
| 456 | 456 | } |
@@ -5,9 +5,9 @@ discard block |
||
| 5 | 5 | class ResourceInfo |
| 6 | 6 | { |
| 7 | 7 | /* 以下属性是资源ID所需的属性*/ |
| 8 | - protected $namespace; //空间名,必须 |
|
| 9 | - protected $dir; //路径 |
|
| 10 | - protected $name; //文件名信息 |
|
| 8 | + protected $namespace; //空间名,必须 |
|
| 9 | + protected $dir; //路径 |
|
| 10 | + protected $name; //文件名信息 |
|
| 11 | 11 | /* 以下属性是资源ID所需的属性*/ |
| 12 | 12 | /** |
| 13 | 13 | * ResourceOption的构造函数 |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | /**对URL中文进行编码*/ |
| 63 | 63 | protected function urlencode_ch($str) |
| 64 | 64 | { |
| 65 | - return preg_replace_callback('/[^\0-\127]+/', function ($match) { |
|
| 65 | + return preg_replace_callback('/[^\0-\127]+/', function($match) { |
|
| 66 | 66 | return urlencode($match[0]); |
| 67 | 67 | }, $str); |
| 68 | 68 | } |
@@ -6,15 +6,15 @@ discard block |
||
| 6 | 6 | class MediaEncodeOption extends MediaResOption |
| 7 | 7 | { |
| 8 | 8 | /* 以下属性是"视频转码"方法必须的属性 */ |
| 9 | - private $encodeTemplate; //模板名称。可以设置系统或者用户自定义模板。用户模板名称可以登录后台查看和设置,系统模板见附录系统模板列表 |
|
| 10 | - public $usePreset = 0; //是否使用系统模板。默认0。如果为1,则encodeTemplate必须设置系统模板名称 |
|
| 11 | - public $force = 0; //是否强制覆盖。默认0,如果为1,当output文件已经存在的时候会强制覆盖,否则不执行转码并结束任务 |
|
| 9 | + private $encodeTemplate; //模板名称。可以设置系统或者用户自定义模板。用户模板名称可以登录后台查看和设置,系统模板见附录系统模板列表 |
|
| 10 | + public $usePreset = 0; //是否使用系统模板。默认0。如果为1,则encodeTemplate必须设置系统模板名称 |
|
| 11 | + public $force = 0; //是否强制覆盖。默认0,如果为1,当output文件已经存在的时候会强制覆盖,否则不执行转码并结束任务 |
|
| 12 | 12 | /* 以下属性是"视频转码"方法可选的属性 */ |
| 13 | - private $watermark; //水印资源 |
|
| 14 | - private $watermarkTemplate; //用户自定义水印模板 |
|
| 15 | - private $notifyUrl; //通知url,任务结束之后会调用这个url |
|
| 16 | - private $seek; //截取音视频的开始位置 |
|
| 17 | - private $duration; //截取音视频的长度 |
|
| 13 | + private $watermark; //水印资源 |
|
| 14 | + private $watermarkTemplate; //用户自定义水印模板 |
|
| 15 | + private $notifyUrl; //通知url,任务结束之后会调用这个url |
|
| 16 | + private $seek; //截取音视频的开始位置 |
|
| 17 | + private $duration; //截取音视频的长度 |
|
| 18 | 18 | |
| 19 | 19 | /**设置转码模板。必须。模板在顽兔控制台"多媒体处理"中配置*/ |
| 20 | 20 | public function setEncodeTemplate($encodeTemplate) |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $httpBody .= '¬ifyUrl=' . urlencode($this->notifyUrl); |
| 57 | 57 | } |
| 58 | 58 | if (isset($this->seek)) { |
| 59 | - $httpBody .= '&seek=' . $this->seek; |
|
| 59 | + $httpBody .= '&seek=' . $this->seek; |
|
| 60 | 60 | } |
| 61 | 61 | if (isset($this->duration)) { |
| 62 | 62 | $httpBody .= '&duration=' . $this->duration; |
@@ -138,8 +138,8 @@ discard block |
||
| 138 | 138 | /**多媒体操作的输入输出资源信息。视频截图和视频转码都继承该类*/ |
| 139 | 139 | abstract class MediaResOption |
| 140 | 140 | { |
| 141 | - private $input; //输入的资源 |
|
| 142 | - private $output; //输出的资源 |
|
| 141 | + private $input; //输入的资源 |
|
| 142 | + private $output; //输出的资源 |
|
| 143 | 143 | /**设置输入的文件。*/ |
| 144 | 144 | public function setInputResource($namespace = null, $dir = null, $name = null) |
| 145 | 145 | { |
@@ -10,34 +10,34 @@ discard block |
||
| 10 | 10 | public $optionType; |
| 11 | 11 | |
| 12 | 12 | /*以下属性是上传时的可选参数。即Rest API中Http请求Body中所需的可选参数*/ |
| 13 | - public $dir; // 顽兔空间的图片路径(如果UploadPolicy中不指定dir属性,则生效) |
|
| 14 | - public $name; // 上传到服务端的文件名(如果UploadPolicy中不指定name属性,则生效) |
|
| 15 | - public $metaArray; // 用户自定义的文件meta信息("meta-"为参数前缀, "*"为用户用于渲染的自定义Meta信息名) |
|
| 16 | - public $varArray; // 用户自定义的魔法变量("var-"为参数前缀, "*"为用户用于渲染的自定义魔法变量名) |
|
| 17 | - private $md5; // 文件md5值(推荐提供此参数进行一致性检查) |
|
| 18 | - private $size; // 文件大小 |
|
| 19 | - private $content; // 文件内容(在http请求体Body中必须位于参数的最后一位) |
|
| 13 | + public $dir; // 顽兔空间的图片路径(如果UploadPolicy中不指定dir属性,则生效) |
|
| 14 | + public $name; // 上传到服务端的文件名(如果UploadPolicy中不指定name属性,则生效) |
|
| 15 | + public $metaArray; // 用户自定义的文件meta信息("meta-"为参数前缀, "*"为用户用于渲染的自定义Meta信息名) |
|
| 16 | + public $varArray; // 用户自定义的魔法变量("var-"为参数前缀, "*"为用户用于渲染的自定义魔法变量名) |
|
| 17 | + private $md5; // 文件md5值(推荐提供此参数进行一致性检查) |
|
| 18 | + private $size; // 文件大小 |
|
| 19 | + private $content; // 文件内容(在http请求体Body中必须位于参数的最后一位) |
|
| 20 | 20 | |
| 21 | 21 | /*以下属性是用户根据自己应用需求,可选的配置*/ |
| 22 | - public $blockSize; // 文件分片的大小。针对分片上传。 |
|
| 23 | - public $timeout; // 进行http连接的超时时间 |
|
| 24 | - public $httpReTry; // http失败自动重试。0 or 1 |
|
| 22 | + public $blockSize; // 文件分片的大小。针对分片上传。 |
|
| 23 | + public $timeout; // 进行http连接的超时时间 |
|
| 24 | + public $httpReTry; // http失败自动重试。0 or 1 |
|
| 25 | 25 | |
| 26 | 26 | /*以下属性是用于分片上传时的参数,仅用于分片上传。用户在调用分片上传时可以选择配置。*/ |
| 27 | - private $uploadId; // OSS分片上传ID(OSS用于区分上传的id) |
|
| 28 | - private $uniqueId; // 服务上传唯一ID(多媒体服务用于区分上传的id) |
|
| 29 | - private $partNumber; // 分片文件块上传成功后返回的文件块编号 |
|
| 30 | - private $eTag; // 分片文件块上传成功后返回的Tag标签(由md5和其他标记组成) |
|
| 31 | - private $array_PartNum_ETag; // 分片上传服务端返回的所有 块编号partNumber 和 标记ETag |
|
| 27 | + private $uploadId; // OSS分片上传ID(OSS用于区分上传的id) |
|
| 28 | + private $uniqueId; // 服务上传唯一ID(多媒体服务用于区分上传的id) |
|
| 29 | + private $partNumber; // 分片文件块上传成功后返回的文件块编号 |
|
| 30 | + private $eTag; // 分片文件块上传成功后返回的Tag标签(由md5和其他标记组成) |
|
| 31 | + private $array_PartNum_ETag; // 分片上传服务端返回的所有 块编号partNumber 和 标记ETag |
|
| 32 | 32 | |
| 33 | 33 | public function __construct() |
| 34 | 34 | { |
| 35 | 35 | $this->optionType = UpOptionType::COMMON_UPLOAD_TYPE; //默认普通上传类型 |
| 36 | 36 | $this->metaArray = array(); |
| 37 | 37 | $this->varArray = array(); |
| 38 | - $this->blockSize = Conf::BLOCK_DEFF_SIZE; //默认2M |
|
| 39 | - $this->timeout = Conf::HTTP_TIMEOUT; //默认超时30s |
|
| 40 | - $this->httpReTry = Conf::HTTP_RETRY; //默认重试 |
|
| 38 | + $this->blockSize = Conf::BLOCK_DEFF_SIZE; //默认2M |
|
| 39 | + $this->timeout = Conf::HTTP_TIMEOUT; //默认超时30s |
|
| 40 | + $this->httpReTry = Conf::HTTP_RETRY; //默认重试 |
|
| 41 | 41 | $this->array_PartNum_ETag = array(); |
| 42 | 42 | } |
| 43 | 43 | /**得到上传时http请求体所需的参数*/ |
@@ -174,9 +174,9 @@ discard block |
||
| 174 | 174 | class UpOptionType |
| 175 | 175 | { |
| 176 | 176 | //下面的常量用于标识UploadOption对象适用的类型 |
| 177 | - const COMMON_UPLOAD_TYPE = 0; //普通上传时的UploadOption类型 |
|
| 178 | - const BLOCK_INIT_UPLOAD = 1; //分片初始化时的UploadOption类型 |
|
| 179 | - const BLOCK_RUN_UPLOAD = 2; //分片上传过程中的UploadOption类型 |
|
| 180 | - const BLOCK_COMPLETE_UPLOAD = 3; //分片上传完成时的UploadOption类型 |
|
| 181 | - const BLOCK_CANCEL_UPLOAD = 4; //分片上传取消时的UploadOption类型 |
|
| 177 | + const COMMON_UPLOAD_TYPE = 0; //普通上传时的UploadOption类型 |
|
| 178 | + const BLOCK_INIT_UPLOAD = 1; //分片初始化时的UploadOption类型 |
|
| 179 | + const BLOCK_RUN_UPLOAD = 2; //分片上传过程中的UploadOption类型 |
|
| 180 | + const BLOCK_COMPLETE_UPLOAD = 3; //分片上传完成时的UploadOption类型 |
|
| 181 | + const BLOCK_CANCEL_UPLOAD = 4; //分片上传取消时的UploadOption类型 |
|
| 182 | 182 | } |
@@ -6,24 +6,24 @@ |
||
| 6 | 6 | class UploadPolicy |
| 7 | 7 | { |
| 8 | 8 | /*如下属性是必须的[The following attributes are required]*/ |
| 9 | - public $namespace; // 多媒体服务的空间名[media namespace name] |
|
| 10 | - public $bucket; // OSS的空间名[media bucket name] |
|
| 11 | - public $insertOnly; // 是否可覆盖[upload mode. it's not allowd uploading the same name files] |
|
| 12 | - public $expiration; // 过期时间[expiration time, unix time, in milliseconds] |
|
| 9 | + public $namespace; // 多媒体服务的空间名[media namespace name] |
|
| 10 | + public $bucket; // OSS的空间名[media bucket name] |
|
| 11 | + public $insertOnly; // 是否可覆盖[upload mode. it's not allowd uploading the same name files] |
|
| 12 | + public $expiration; // 过期时间[expiration time, unix time, in milliseconds] |
|
| 13 | 13 | |
| 14 | 14 | /*如下属性是可选的[The following attributes are optional]*/ |
| 15 | - public $detectMime = Conf::DETECT_MIME_TRUE; // 是否进行类型检测[is auto detecte media file mime type, default is true] |
|
| 16 | - public $dir; // 路径[media file dir, magic vars and custom vars are supported] |
|
| 17 | - public $name; // 上传到服务端的文件名[media file name, magic vars and custom vars are supported] |
|
| 18 | - public $sizeLimit; // 文件大小限制[upload size limited, in bytes] |
|
| 19 | - public $mimeLimit; // 文件类型限制[upload mime type limited] |
|
| 20 | - public $callbackUrl; // 回调URL [callback urls, ip address is recommended] |
|
| 21 | - public $callbackHost; // 回调时Host [callback host] |
|
| 22 | - public $callbackBody; // 回调时Body [callback body, magic vars and custom vars are supported] |
|
| 23 | - public $callbackBodyType; // 回调时Body类型 [callback body type, default is 'application/x-www-form-urlencoded; charset=utf-8'] |
|
| 24 | - public $returnUrl; // 上传完成之后,303跳转的Url [return url, when return code is 303] |
|
| 25 | - public $returnBody; // 上传完成返回体 [return body, magic vars and custom vars are supported] |
|
| 26 | - public $mediaEncode; // 上传音视频时,可以指定转码策略[media encode policy after upload task has been completed. it's json string] |
|
| 15 | + public $detectMime = Conf::DETECT_MIME_TRUE; // 是否进行类型检测[is auto detecte media file mime type, default is true] |
|
| 16 | + public $dir; // 路径[media file dir, magic vars and custom vars are supported] |
|
| 17 | + public $name; // 上传到服务端的文件名[media file name, magic vars and custom vars are supported] |
|
| 18 | + public $sizeLimit; // 文件大小限制[upload size limited, in bytes] |
|
| 19 | + public $mimeLimit; // 文件类型限制[upload mime type limited] |
|
| 20 | + public $callbackUrl; // 回调URL [callback urls, ip address is recommended] |
|
| 21 | + public $callbackHost; // 回调时Host [callback host] |
|
| 22 | + public $callbackBody; // 回调时Body [callback body, magic vars and custom vars are supported] |
|
| 23 | + public $callbackBodyType; // 回调时Body类型 [callback body type, default is 'application/x-www-form-urlencoded; charset=utf-8'] |
|
| 24 | + public $returnUrl; // 上传完成之后,303跳转的Url [return url, when return code is 303] |
|
| 25 | + public $returnBody; // 上传完成返回体 [return body, magic vars and custom vars are supported] |
|
| 26 | + public $mediaEncode; // 上传音视频时,可以指定转码策略[media encode policy after upload task has been completed. it's json string] |
|
| 27 | 27 | |
| 28 | 28 | public function __construct($option) |
| 29 | 29 | { |