npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lantsang/nestjs-aliyun-oss

v0.0.5

Published

阿里云OSS nestjs封装

Downloads

20

Readme

nestjs 阿里云OSS插件

注意:仍在开发中,目前仅在内部使用

使用说明

  • 外部人员仅供参考,请不要用于生产环境,因此导致的事故后果请自行承担。
  • TS target es2019
  • 支持集群

安装

$ npm i @lantsang/nestjs-aliyun-oss or $ yarn add @lantsang/nestjs-aliyun-oss 推荐使用yarn

引入

import { AliOSSModule } from '@lantsang/nestjs-aliyun-oss'

@Module({
  imports: [
    AliOSSModule.register({
      region: 'oss-cn-beijing',
      endpoint: 'https://oss-cn-beijing.aliyuncs.com', 
      bucket: 'vue-test-iric',
      accessKeyId: '********',
      accessKeySecret: '******'
    })
  ]
})
export class AppModule { }

方法使用

Put上传文件

import { Inject, Injectable } from '@nestjs/common';
import { AliOSSService } from "@lantsang/nestjs-aliyun-oss";

@Injectable()
export class TestService {
  constructor(private readonly aliOSSService: AliOSSService) {}

  /**
   * 上传文件到OSS上,返回oss中文件url地址
   * @param remotePath OSS远端路径, 例如:'upload/123.txt'
   * @param localPath 文件本地路径,绝对路径,使用path.join()方法获取
   */
  async upload(remotePath: string, localPath: string):Promise<string>{
    const { name, url, res } = await this.aliOSSService.putUpload(remotePath,localPath);
    return url;
  }
}

检测文件是否存在

const exist = await this.aliOSSService.fileExist('upload/123.txt');

删除文件

注意: 删除文件首先先保证oss中存在此文件,如果不存在会抛错,删除并不会返回删除成功与否结果,这个问题具体看代码中注释。

await this.aliOSSService.delete('upload/123.txt');

拷贝文件

注意: 如果目标文件不存在会报错。

const copyResult = await this.aliOSSService.copy('upload/123.txt','upload/123_copy.txt');