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

@xgoteam/upload-file

v1.0.22

Published

Ali Cloud OSS upload file components

Downloads

5

Readme

@xgoteam/upload-file

阿里云OSS文件上传模块 npm 传送门 https://www.npmjs.com/package/@xgoteam/upload-file

上传文件到指定的阿里云OSS bucket

Getting Started 使用指南

请确保安装node环境和安装npm

Installation 安装

使用 npm 命令安装模块

$ npm install @xgoteam/upload-file

Usage example 使用示例

import UploadFile from '@xgoteam/upload-file'
import { driverRequest } from '@/api/Requests'
// 使用vant-ui为例
import { Toast } from 'vant'

const uploadFile = new UploadFile({
  request: driverRequest,
  type: 'privateImg',
  bizName: 'driver_register',
  file,
  showError: err => {
    // 输出错误信息
    Toast({
      message: err.message,
      position: 'bottom'
    })
  }
})
uploadFile.upload().then(res =>{
  // 上传成功后执行
  // 上传文件域名
  console.log(res.domain)
  // 上传文件路径
  console.log(res.data.name)
})

API

Props(UploadFile)

参数 | 说明 | 类型 | 默认值 | 版本 ---- | --- | ---- | --- | ---- request | 推荐使用,axios请求对象,接收项目中@/api/Requests下的域名含有鉴权接口的request对象 | Object | - | - domain | 非必填,如果没有指定request, 请提供一个含有鉴权接口的域名 | String | - | - token | 非必填,如果没有指定request,且该接口需要使用token请提供 | String | '' | - type | 上传bucket类型,可选值为 public(公有域) privateImg(私有域图片) | String | 'public' | - authPath | 非必填,如果该业务需要其他鉴权接口地址,请提供,就不需要指定type | String | '' | - file | 必填,上传文件的File对象 | Object | '' | - bizName | 必填,具体的业务名称,要求尽量使用小写字母和用”_“分隔单词 | String | '' | - showError | 非必填,错误消息回调,由于每个项目使用的ui框架不同,所以需要手动调用 | Function | '' | - beforeGetAuth | 非必填,调用鉴权接口之前执行的函数 | Function | '' | - beforeUpload | 非必填,调用上传文件方法之前执行的函数 | Function | '' | -

Methods(UploadFile)

方法名 | 说明 | 返回值 | 版本 ---- | --- | ---- | --- | ---- upload | 执行上传文件 | <Promise>: { data: 'oss返回的json' , domain: 'bucket域名' } | -

tips

  1. 上传成功后文件的地址应为:
    
    const url = `//${domain}${data.name}`
    
  2. 由于考虑到http与https兼容问题,请注意上传到后端的文件地址不应该携带任何通信协议(protocol)

Contributing 贡献指南

  1. 准备:请确保你的npm库源地址是官方npm

    
    npm config set registry https://registry.npmjs.org/
    
  2. 注册:请先在 官网用您的企业邮箱注册一个账号,然后通知xgoteam npm账号管理员发出邀请,加入本项目的维护者。

  3. 登录:使用以下命令登录npm账号

    $ npm login
    输入你的用户名与密码
  4. 【请不要在master分支直接改代码!】新建一个分支,在新的分支上修改代码,当修改完毕,请先在npm上直接发布代码来验证你的修改

  5. 测试:首先在package.json文件内修改npm发布版本号,npm发布版本号必需是唯一的!不然会导致发布失败

    {
      "name": "@xgoteam/upload-file",
      //修改新的版本号
      "version": "1.0.14",
      "description": "Ali Cloud OSS upload file components",
    }
  6. 版本号编码规则:X.XXX.XXX 【X(重构整个项目的修改).XXX(阶段性修改:一般为功能拓展、内部方法实现重构).XXX(测试版本)】

  7. 打包:请先在运行以下命令,调用webpack进行本地打包。因为,最终项目中使用的代码是webpack进行处理压缩后的代码(./dist/index.js)

    $ npm run build
  8. 上传:上传到npm库,运行以下命令

    $ npm publish
  9. 定版:测试通过后,请把当前分支合并到master,并在master上打上tag(版本跟package.json 的version相同)

Release History 版本历史

  • 1.0.16
    • 完成上传模块功能