Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meibuyu-common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
without authentication
meibuyu-common
Commits
50ef9161
Commit
50ef9161
authored
Feb 09, 2023
by
chentianyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
oss服务
parent
ac49e396
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
13 deletions
+46
-13
HttpResponseException.php
src/Exceptions/HttpResponseException.php
+11
-0
FileModel.php
src/UploadOss/FileModel.php
+29
-0
UploadOssService.php
src/UploadOss/UploadOssService.php
+6
-13
No files found.
src/Exceptions/HttpResponseException.php
0 → 100644
View file @
50ef9161
<?php
declare
(
strict_types
=
1
);
namespace
Meibuyu\Common\Exceptions
;
class
HttpResponseException
extends
\Exception
{
}
\ No newline at end of file
src/UploadOss/FileModel.php
0 → 100644
View file @
50ef9161
<?php
declare
(
strict_types
=
1
);
namespace
Meibuyu\Common\UploadOss
;
use
Hyperf\DbConnection\Model\Model
;
/**
* 模型类 File
* @package App\Model
* @property integer $id
* @property string $type 文件类型
* @property string $module 模块
* @property string $name 文件名
* @property string $path 文件路径
* @property string $ext 文件后缀
* @property string $user_id 用户id
* @property string $size 文件大小
* @property string $created_at
*/
class
FileModel
extends
Model
{
const
UPDATED_AT
=
null
;
protected
$fillable
=
[
'type'
,
'module'
,
'name'
,
'path'
,
'ext'
,
'user_id'
,
'size'
];
}
src/UploadOss/UploadOssService.php
View file @
50ef9161
<?php
/**
* Created by PhpStorm.
* User: Zero
* Date: 2021/06/24
* Time: 15:59:06
*/
namespace
App\Service
s
;
namespace
Meibuyu\Common\UploadOs
s
;
use
Meibuyu\Rpc\UploadOss\FileModel
;
use
Hyperf\Contract\ConfigInterface
;
use
League\Flysystem\Filesystem
;
use
Hyperf\Filesystem\FilesystemFactory
;
use
Hyperf\HttpMessage\Upload\UploadedFile
;
use
League\Flysystem\FileExistsException
;
use
Meibuyu\
Micro
\Exceptions\HttpResponseException
;
use
Meibuyu\
Common
\Exceptions\HttpResponseException
;
use
Psr\Container\ContainerInterface
;
class
UploadOssService
...
...
@@ -59,7 +52,7 @@ class UploadOssService
* @param \Hyperf\HttpMessage\Upload\UploadedFile $image
* @param string $path
* @return array
* @throws \Meibuyu\
Micro
\Exceptions\HttpResponseException
* @throws \Meibuyu\
Common
\Exceptions\HttpResponseException
* @author Zero
*/
public
function
uploadImage
(
UploadedFile
$image
,
string
$path
,
string
$userId
)
...
...
@@ -87,12 +80,12 @@ class UploadOssService
* @param \Hyperf\HttpMessage\Upload\UploadedFile $image
* @param string $path
* @return array
* @throws \Meibuyu\
Micro
\Exceptions\HttpResponseException
* @throws \Meibuyu\
Common
\Exceptions\HttpResponseException
* @author Zero
*/
public
function
uploadFile
(
UploadedFile
$file
,
string
$path
,
string
$userId
,
array
$options
=
[])
{
$filePath
=
'
meibuyu
/'
.
$this
->
appDev
.
"/
$path
/images/"
.
today
()
.
"/
$userId
/"
.
$file
->
getClientFilename
();
$filePath
=
'
oss2
/'
.
$this
->
appDev
.
"/
$path
/images/"
.
today
()
.
"/
$userId
/"
.
$file
->
getClientFilename
();
$this
->
upload
(
$file
,
$filePath
,
$options
);
$model
=
new
FileModel
();
$model
=
$model
->
newInstance
([
...
...
@@ -113,7 +106,7 @@ class UploadOssService
* @param $path
* @param array $options
* @return bool
* @throws \Meibuyu\
Micro
\Exceptions\HttpResponseException
* @throws \Meibuyu\
Common
\Exceptions\HttpResponseException
* @author Zero
*/
public
function
upload
(
UploadedFile
$file
,
string
$path
,
array
$options
=
[])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment