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

@lx-frontend/wx-file-upload

v1.0.2

Published

立新文件上传通用库,支持小程序与网页

Downloads

95

Readme

@lx-frontend/file-upload

详细用法请查阅文档网页

小程序和网页通用上传资源库,用户上传图片、音频、文件

Usage

在小程序中:

  1. 引入包
const fileUpload = require('@lx-frontend/file-upload');

上传图片

wx.chooseImage({
  'sizeType': ['compressed'],
  success: async (res) => {
    console.log('chooseImage res', res)
    const [ localPath ] = res.tempFilePaths
    const upRes = await fileUpload({
      platform: 'mp',
      uploadType: 'image',
      configUrl: 'https://q.test.dos.lixinchuxing.cn/api/v1/upload/em_addition_repair_reason',
      filePath: localPath,
      header: { // 传递鉴权头2选1
        Cookie: 'session=15417714-20a3-4458-94f9-fd83ef67cb6a',
        'access-token': 'xxx'
      }
    })

    console.log('upRes', upRes)
  }
})

返回数据格式:

{
    "code":0,
    "data":[
        {
            "image":"https://test-images-cdn.lxusercontent.com/em_addition/repair_reason/g_zhongsheng/2021-02-20/25Lozpp9wHGgEUG3mBZELT.png",
            "key":"",
            "thumbnail_image":"https://test-images-cdn.lxusercontent.com/em_addition/repair_reason/g_zhongsheng/2021-02-20/25Lozpp9wHGgEUG3mBZELT.png?x-oss-process=image/resize,w_300/quality,q_80",
            "upload_image":"https://test-images-cdn.lxusercontent.com/em_addition/repair_reason/g_zhongsheng/2021-02-20/25Lozpp9wHGgEUG3mBZELT.png"
        }
    ],
    "message":"ok"
}

上传音频

const record = wx.getRecorderManager()
record.start({
  format: 'mp3'
})

record.onStop(async function (res) {
  console.log('record res', res)
  const recordRes = await fileUpload({
    platform: 'mp',
    uploadType: 'audio',
    configUrl: 'https://q.test.dos.lixinchuxing.cn/api/v1/upload/em_addition_repair_reason_audio',
    filePath: res.tempFilePath,
    header: {
      Cookie: 'session=15417714-20a3-4458-94f9-fd83ef67cb6a'
    }
  })
  console.log('recordRes', recordRes)
})

setTimeout(() => {
  record.stop()
}, 2000)

返回数据格式:

{
    "code":0,
    "data":[
        {
            "key":"",
            "url":"https://test-images-cdn.lxusercontent.com/em_addition/repair_reason_audio/g_zhongsheng/2021-02-20/ffhxQtWr7Nfc7isziE28Tm.mp3"
        }
    ],
    "message":"ok"
}

参数说明

| 参数 | 说明 | 类型 | 可选值 | 默认值 | 必填 | | ---------- | ------------------------------------------------------------ | ------ | ----------- | ------ | ---- | | platform | 平台 | String | mp/web | Mp | 是 | | uploadType | 上传资源类型 | String | Image/audio | image | 是 | | configUrl | 每个新类型上传后台都会给一个 type,追加到项目上传url后面,格式:https://项目域名/api/v1/upload/${type},举例: https://q.test.dos.lixinchuxing.cn/api/v1/upload/em_addition_repair_reason | String | - | - | 是 | | filePath | 小程序为选取资源的 tempFilePaths 字段,web 为form表单选择文件字段。 | String | - | - | 是 | | header | 鉴权请求头,需要拿项目的 session/access-token 去指定url换成上传配置。举例:{ Cookie: 'session=15417714-20a3-4458-94f9-fd83ef67cb6a' } 或 { 'access-token': 'xxx' } | Object | - | {} | 是 |