小程序使用七牛云上传的实例

小程序中还是相对没那么麻烦:官网文档,如图下载sdk
在这里插入图片描述

	//这里忘记自己为什么引用两个了
	import { upload } from '../../../../utils/qiniuUploader.js'

使用:

		// 下面的变量都需要根据自己的实际情况填写
		upload({
            filePath: filePath.path,
            options: {
              key: filePath.name ,          // 可选
              region: 'ECN',       // 可选(默认为'ECN')
              domain: '',//七牛云的地址
              uptoken: that.data.upToken,      // 以下三选一
              uptokenURL: '',
              uptokenFunc: () => {
                return that.data.upToken;
              },
              shouldUseQiniuFileName: true // 默认false
            },
            before: () => {
              // 上传前
              console.log('before upload');
            },
            success: (res) => {
              console.log(res)
              that.setData({
                'imageURL': res.imageURL,
              });
            },
            fail: (err) => {
              console.log('error:' + err);
            },
            progress: (res) => {
              console.log('上传进度', res.progress)
              console.log('已经上传的数据长度', res.totalBytesSent)
              console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
            },
            complete: (err) => {
              // 上传结束
              console.log('upload complete');
            }
          });

这里根据我自己的使用,下载的SDK文件改动过的sdk 我也改动了一些:

发布了50 篇原创文章 · 获赞 4 · 访问量 1288

猜你喜欢

转载自blog.csdn.net/weixin_43910427/article/details/104429235