新增七牛云上传
This commit is contained in:
@@ -28,8 +28,9 @@ return [
|
||||
|
||||
//上传类型
|
||||
'upload_types' => [
|
||||
'local' => '本地存储',
|
||||
'oss' => '阿里云oss',
|
||||
'cos' => '腾讯云cos'
|
||||
'local' => '本地存储',
|
||||
'oss' => '阿里云oss',
|
||||
'cos' => '腾讯云cos',
|
||||
'qnoss' => '七牛云'
|
||||
],
|
||||
];
|
||||
@@ -9,6 +9,9 @@ use think\facade\Env;
|
||||
use think\file\UploadedFile;
|
||||
use think\helper\Str;
|
||||
use Qcloud\Cos\Client;
|
||||
use Exception;
|
||||
use Qiniu\Storage\UploadManager;
|
||||
use Qiniu\Auth;
|
||||
|
||||
class UploadService
|
||||
{
|
||||
@@ -161,7 +164,7 @@ class UploadService
|
||||
if (empty($location)) return ['code' => 0, 'data' => '上传至COS失败'];
|
||||
$location = 'https://' . $location;
|
||||
$this->setSaveData($file);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
return ['code' => 0, 'data' => $e->getMessage()];
|
||||
}
|
||||
$data = ['url' => $location];
|
||||
@@ -172,6 +175,35 @@ class UploadService
|
||||
return ['code' => 0, 'data' => $data];
|
||||
}
|
||||
|
||||
/**
|
||||
* 七牛云
|
||||
*
|
||||
* @param UploadedFile $file
|
||||
* @param string $type
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function qnoss(UploadedFile $file, string $type = ''): array
|
||||
{
|
||||
if (!$file->isValid()) return ['code' => 1, 'data' => '上传验证失败'];
|
||||
$uploadMgr = new UploadManager();
|
||||
$config = $this->getConfig();
|
||||
$accessKey = $config['qnoss_access_key'];
|
||||
$secretKey = $config['qnoss_secret_key'];
|
||||
$bucket = $config['qnoss_bucket'];
|
||||
$domain = $config['qnoss_domain'];
|
||||
$auth = new Auth($accessKey, $secretKey);
|
||||
$token = $auth->uploadToken($bucket);
|
||||
$object = $this->setFilePath($file, Env::get('EASYADMIN.OSS_STATIC_PREFIX', 'easyadmin8') . '/');
|
||||
list($ret, $error) = $uploadMgr->putFile($token, $object, $file->getRealPath());
|
||||
if (empty($ret)) return ['code' => 0, 'data' => $error->getResponse()->error ?? '上传失败,请检查七牛云相关参数配置'];
|
||||
$url = $domain . "/" . $ret['key'];
|
||||
$data = ['url' => $url];
|
||||
$this->setSaveData($file);
|
||||
$this->save($url);
|
||||
return ['code' => 1, 'data' => $data];
|
||||
}
|
||||
|
||||
protected function save(string $url = ''): bool
|
||||
{
|
||||
$data = $this->saveData;
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
"phpoffice/phpspreadsheet": "^1.28",
|
||||
"myclabs/php-enum": "^1.8",
|
||||
"ext-json": "*",
|
||||
"qiniu/php-sdk": "*"
|
||||
"qiniu/php-sdk": "v7.11.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/var-dumper": "^4.2",
|
||||
|
||||
39
composer.lock
generated
39
composer.lock
generated
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "bcdc64a64bbf0b2934132cd1981c572b",
|
||||
"content-hash": "ef242a20ba800f28afba2ecd5b7dcba8",
|
||||
"packages": [
|
||||
{
|
||||
"name": "adbario/php-dot-notation",
|
||||
@@ -1644,16 +1644,16 @@
|
||||
},
|
||||
{
|
||||
"name": "myclabs/php-enum",
|
||||
"version": "1.8.3",
|
||||
"version": "1.8.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/myclabs/php-enum.git",
|
||||
"reference": "b942d263c641ddb5190929ff840c68f78713e937"
|
||||
"reference": "a867478eae49c9f59ece437ae7f9506bfaa27483"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/myclabs/php-enum/zipball/b942d263c641ddb5190929ff840c68f78713e937",
|
||||
"reference": "b942d263c641ddb5190929ff840c68f78713e937",
|
||||
"url": "https://api.github.com/repos/myclabs/php-enum/zipball/a867478eae49c9f59ece437ae7f9506bfaa27483",
|
||||
"reference": "a867478eae49c9f59ece437ae7f9506bfaa27483",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
@@ -1675,7 +1675,10 @@
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"MyCLabs\\Enum\\": "src/"
|
||||
}
|
||||
},
|
||||
"classmap": [
|
||||
"stubs/Stringable.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
@@ -1694,7 +1697,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/myclabs/php-enum/issues",
|
||||
"source": "https://github.com/myclabs/php-enum/tree/1.8.3"
|
||||
"source": "https://github.com/myclabs/php-enum/tree/1.8.4"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -1706,7 +1709,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2021-07-05T08:18:36+00:00"
|
||||
"time": "2022-08-04T09:53:51+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpoffice/phpspreadsheet",
|
||||
@@ -2300,16 +2303,16 @@
|
||||
},
|
||||
{
|
||||
"name": "qiniu/php-sdk",
|
||||
"version": "v7.4.1",
|
||||
"version": "v7.11.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/qiniu/php-sdk.git",
|
||||
"reference": "10c7ead8357743b4b987a335c14964fb07700d57"
|
||||
"reference": "9ee81f0acd57fa7bb435ffe9e515d7a9fdd0489b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/qiniu/php-sdk/zipball/10c7ead8357743b4b987a335c14964fb07700d57",
|
||||
"reference": "10c7ead8357743b4b987a335c14964fb07700d57",
|
||||
"url": "https://api.github.com/repos/qiniu/php-sdk/zipball/9ee81f0acd57fa7bb435ffe9e515d7a9fdd0489b",
|
||||
"reference": "9ee81f0acd57fa7bb435ffe9e515d7a9fdd0489b",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
@@ -2319,17 +2322,19 @@
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"myclabs/php-enum": "~1.5.2 || ~1.6.6 || ~1.7.7 || ~1.8.4",
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"paragonie/random_compat": ">=2",
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"squizlabs/php_codesniffer": "~3.6"
|
||||
"phpunit/phpunit": "^4.8 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4",
|
||||
"squizlabs/php_codesniffer": "^2.3 || ~3.6"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/Qiniu/functions.php"
|
||||
"src/Qiniu/functions.php",
|
||||
"src/Qiniu/Http/Middleware/Middleware.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Qiniu\\": "src/Qiniu"
|
||||
@@ -2356,9 +2361,9 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/qiniu/php-sdk/issues",
|
||||
"source": "https://github.com/qiniu/php-sdk/tree/v7.4.1"
|
||||
"source": "https://github.com/qiniu/php-sdk/tree/v7.11.0"
|
||||
},
|
||||
"time": "2021-09-24T09:39:16+00:00"
|
||||
"time": "2023-09-05T12:33:39+00:00"
|
||||
},
|
||||
{
|
||||
"name": "ralouphie/getallheaders",
|
||||
|
||||
Reference in New Issue
Block a user