nest-qiniu-sdk
qiniu sdk for nestjs
安装
yarn add nest-qiniu-sdk
使用
同步注册
import {Module} from '@nestjs/common'
import {AppController} from './app.controller'
import {QiniuModule, zone} from 'nest-qiniu-sdk'
@Module({
imports: [
QiniuModule.register({
global: true,
access_key: 'access_key',
secret_key: 'secret_key',
bucket: 'bucket',
domain: 'http://bucket.test',
}),
],
controllers: [AppController],
})
export class AppModule {
}
import {Controller, Get} from '@nestjs/common'
import {QiniuService, util} from 'nest-qiniu-sdk'
@Controller()
export class AppController {
constructor(private readonly QiniuService: QiniuService) {
}
@Get()
hiQiniu(@Request() req): any {
let options = this.QiniuService.getOptions(),
access_key = this.QiniuService.getOptions('access_key'),
secret_key = this.QiniuService.getOptions('secret_key'),
zone = this.QiniuService.getZone(),
bucket = this.QiniuService.getBucket(),
domain = this.QiniuService.getDomain()
let mac = this.QiniuService.mac(),
cdnManager = this.QiniuService.cdnManager(),
putPolicy = this.QiniuService.putPolicy({}),
formUploader = this.QiniuService.formUploader(),
bucketManager = this.QiniuService.bucketManager(),
operationManager = this.QiniuService.operationManager()
let key = 'file_path',
expires = 60
let get_upload_token = this.QiniuService.getUploadToken({
scope: bucket,
insertOnly: 1,
expires,
})
let download_public_url = this.QiniuService.getPublicDownloadUrl(key)
let download_private_url = this.QiniuService.getPrivateDownloadUrl(key, expires)
let is_qiniu_callback = this.QiniuService.getIsQiniuCallback('request_full_url', req.headers['authorization'], req.body)
let fetch_url = 'http://devtools.qiniu.com/qiniu.png'
bucketManager.fetch(fetch_url, bucket, key, (err, respBody, respInfo) => {
console.log(err, respBody, respInfo)
})
let isTimestampExpired = util.isTimestampExpired(1675274522)
}
}
异步注册
todo
参考