清华大学--赵志磊 七牛云 云存储图片的上传和浏览

 

 

 

 

 

 2、
thinkPHP6的代码 以及扩展安装
先安装扩展
两条命令:
composer require death_satan/think-qiniu-storage -vvv
composer require “overtrue/laravel-filesystem-qiniu” -vvv

 上图代码
‘qiniu’ => [
‘type’=>’qiniu’,
‘accessKey’=>’…………………………’,//你的accessKey
‘secretKey’=>’…………………………’,//你的secretKey
‘bucket’=>’…………………………’,//你的存储空间名
‘domain’=>’…………………………’ //你的七牛云加速域名
],

 上图代码:
public function uploadImage(){
$image = \request()->all(‘image’);
$path = Filesystem::disk(‘qiniu’)->putFile(date(‘Y-m-d’),$image,’uniqid’);
return json([
‘code’=>200,
‘msg’=>’上传七牛成功’,
‘data’=>[
‘path’=>$path,
]
]);
}

 3、浏览对应的图片

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在uni-app中上传图片七牛云,可以按照以下步骤进行: 1. 在七牛云上创建一个存储空间,并获取该空间的Access Key和Secret Key。 2. 安装uni-app的官方插件uni-upload,并在项目根目录下的vue.config.js中进行配置,添加以下代码: ``` const qiniuUploader = require('uniapp-qiniu-sdk'); const qiniuOptions = { region: 'your region', // 七牛云存储区域 uptokenURL: 'your uptokenURL', // 服务端提供获取上传凭证的接口 domain: 'your domain', // 七牛云存储空间绑定的域名 }; module.exports = { configureWebpack: { plugins: [ { apply: (compiler) => { compiler.hooks.afterEmit.tapPromise('afterEmit', (compilation) => { return new Promise((resolve, reject) => { qiniuUploader.upload(compilation.assets['your upload file name'].existsAt, 'your key', qiniuOptions, (res) => { console.log(res); resolve(); }, (error) => { console.log(error); reject(); }); }); }); }, }, ], }, }; ``` 3. 在需要上传图片的页面中,添加以下代码: ``` <template> <view> <input type="file" @change="upload"> </view> </template> <script> export default { methods: { upload(event) { const file = event.target.files[0]; qiniuUploader.upload(file, (res) => { console.log(res); }, (error) => { console.log(error); }); }, }, }; </script> ``` 其中,qiniuUploader.upload函数的第一个参数为要上传的文件,第二个参数为上传成功后的回调函数,第三个参数为上传失败后的回调函数。 以上就是在uni-app中上传图片七牛云的基本步骤,具体使用细节可以根据实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

柔情柴少

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值