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

nsc-file

v2.3.9

Published

前端文件操作库

Downloads

43

Readme

安装

# npm
npm i nsc-file --save

# yarn
yarn add nsc-file

使用

除了 uploadValidate 方法, 其他方法都是异步函数

上传

import file from "nsc-file";
const { upload, uploadValidate } = file;

const handleUpload = async () => {
  const params = {}; // 上传参数
  const validResult = uploadValidate(params);
  if (validResult === null) {
    const res = await upload(params);
  } else {
    // 上传参数校验失败显示错误信息
    alert(validResult.msg);
  }
};

也可以不进行参数校验,自己校验通过后直接调用上传方法

下载

import file from "nsc-file";
const { download } = file;

const handleDownload = async () => {
  // 调用download方法默认会自动下载,如果不要自动下载可以传第二个参数false
  download("文件id");

  // 如果需要知道下载结果
  const res = await download("文件id");
  if (res.code !== 200) {
    // 下载失败显示错误信息
    alert(res.msg);
  }
};

download 参数

  • 第一个参数 是文件 id,字符串类型,必填
  • 第二个参数 是否自动下载,默认值true
  • 第三个参数 请求配置选项

uploadValidate 参数

  • 第一个参数 为文件上传参数

  • 第二个参数 是上传最大值配置, 单位为 kb, 如文件最大允许上传 2M{maxSize: 2 * 1024} ,不传则大小无限制

upload方法

第一个参数选项

| 字段 | 类型 | 必传 | 默认值 | 描述 | | --------------- | ---------- | ---- | ------- | -------------------------------- | | serviceName | string | 是 | | 服务名 | | busiName | string | 是 | | 业务名 | | file | File | 是 | | 文件对象 | | allowSuffixList | string[] | 是 | | 允许上传的文件后缀列表 | | suffix | string | 否 | | 文件名后缀,自动获取 | | publicRead | boolean | 否 | false | 是否公共读 | | isThreeD | boolean | 否 | false | 是否三维专业文件 | | imRez | boolean | 否 | false | 是否进行图片压缩,上传图片时可传 |

第二个参数选项为请求配置选项

previewImage 参数

  • 第一个参数 是文件 id, 字符串类型, 必填
  • 第二个参数 是配置参数, 可以用来配置预览图片大小, 有如下配置参数
    • w 图片宽, 大于 0 的数字 或 "auto"
    • h 图片高, 大于 0 的数字 或 "auto"
    • open 打开新标签页预览图片, 默认false
  • 第三个参数 请求配置选项

previewDocument 参数

  • ** 第一个参数 ** 为文件id参数或者url参数
  • ** 第二个参数 ** 为请求配置选项