Commit 50ef9161 authored by chentianyu's avatar chentianyu

oss服务

parent ac49e396
<?php
declare(strict_types=1);
namespace Meibuyu\Common\Exceptions;
class HttpResponseException extends \Exception
{
}
\ No newline at end of file
<?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'];
}
<?php <?php
/**
* Created by PhpStorm.
* User: Zero
* Date: 2021/06/24
* Time: 15:59:06
*/
namespace App\Services; namespace Meibuyu\Common\UploadOss;
use Meibuyu\Rpc\UploadOss\FileModel;
use Hyperf\Contract\ConfigInterface; use Hyperf\Contract\ConfigInterface;
use League\Flysystem\Filesystem; use League\Flysystem\Filesystem;
use Hyperf\Filesystem\FilesystemFactory; use Hyperf\Filesystem\FilesystemFactory;
use Hyperf\HttpMessage\Upload\UploadedFile; use Hyperf\HttpMessage\Upload\UploadedFile;
use League\Flysystem\FileExistsException; use League\Flysystem\FileExistsException;
use Meibuyu\Micro\Exceptions\HttpResponseException; use Meibuyu\Common\Exceptions\HttpResponseException;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
class UploadOssService class UploadOssService
...@@ -59,7 +52,7 @@ class UploadOssService ...@@ -59,7 +52,7 @@ class UploadOssService
* @param \Hyperf\HttpMessage\Upload\UploadedFile $image * @param \Hyperf\HttpMessage\Upload\UploadedFile $image
* @param string $path * @param string $path
* @return array * @return array
* @throws \Meibuyu\Micro\Exceptions\HttpResponseException * @throws \Meibuyu\Common\Exceptions\HttpResponseException
* @author Zero * @author Zero
*/ */
public function uploadImage(UploadedFile $image, string $path, string $userId) public function uploadImage(UploadedFile $image, string $path, string $userId)
...@@ -87,12 +80,12 @@ class UploadOssService ...@@ -87,12 +80,12 @@ class UploadOssService
* @param \Hyperf\HttpMessage\Upload\UploadedFile $image * @param \Hyperf\HttpMessage\Upload\UploadedFile $image
* @param string $path * @param string $path
* @return array * @return array
* @throws \Meibuyu\Micro\Exceptions\HttpResponseException * @throws \Meibuyu\Common\Exceptions\HttpResponseException
* @author Zero * @author Zero
*/ */
public function uploadFile(UploadedFile $file, string $path, string $userId, array $options = []) 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); $this->upload($file, $filePath, $options);
$model = new FileModel(); $model = new FileModel();
$model = $model->newInstance([ $model = $model->newInstance([
...@@ -113,7 +106,7 @@ class UploadOssService ...@@ -113,7 +106,7 @@ class UploadOssService
* @param $path * @param $path
* @param array $options * @param array $options
* @return bool * @return bool
* @throws \Meibuyu\Micro\Exceptions\HttpResponseException * @throws \Meibuyu\Common\Exceptions\HttpResponseException
* @author Zero * @author Zero
*/ */
public function upload(UploadedFile $file, string $path, array $options = []) public function upload(UploadedFile $file, string $path, array $options = [])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment