Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zan-upload

Package Overview
Dependencies
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zan-upload

这是一个React组件

  • 4.2.5
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
2
Weekly downloads
 
Created
Source

zan-upload

NPM

这是一个图片上传组件

使用方法

微商城

获取 token 接口由原来的 /dock/token.json 替换成以下几种获取 token 的方式:

  1. 微商城公开图片上传:/shop/pubImgUploadToken.json,会在我的文件中显示,图片上传常用接口
  2. 微商城公开音频上传:/shop/pubAudioUploadToken.json,会在我的文件中显示,音频上传常用接口
  3. 存储公开图片上传:/storage/pubImgUploadToken.json,不会在我的文件中显示,如店铺Logo
  4. 存储私有图片上传:/storage/priImgUploadToken.json,不会在我的文件中显示,如店铺认证

具体采用哪个接口可以根据各业务的需求,更多信息可以参考 http://doc.qima-inc.com/pages/viewpage.action?pageId=15168143

非微商城(如美业、餐饮等)

后端需要自己封装token接口

代码演示

:::demo 基础用法

import Upload from 'zan-upload';

class Simple extends React.Component {
    uploadSuccess(data) {
        console.log(data); // eslint-disable-line
    }

    uploadError(data) {
        console.log(data);
    }

    renderTrigger() {
        return <span></span>;
    }

    render() {
        return <Upload
            maxSize={8 * 1000 * 1000}
        	tips="建议尺寸:640 x 640 像素;您可以拖拽图片调整图片顺序。" 
        	onSuccess={this.uploadSuccess} onError={this.uploadError} />;
    }
}

ReactDOM.render(
    <Simple />
    , mountNode
);

:::

:::demo 仅上传本地图片

import Upload from 'zan-upload';

class Simple extends React.Component {
    uploadSuccess(data) {
        console.log(data); // eslint-disable-line
    }

    renderTrigger() {
        return <span></span>;
    }

    render() {
        return <Upload 
        	tips="建议尺寸:640 x 640 像素;您可以拖拽图片调整图片顺序。" 
        	trigger={() => <span>xxx</span>} 
        	onSuccess={this.uploadSuccess} localOnly />;
    }
}

ReactDOM.render(
    <Simple />
    , mountNode
);

:::

:::demo 素材银行

import Upload from 'zan-upload';

class Simple extends React.Component {
    uploadSuccess(data) {
        console.log(data); // eslint-disable-line
    }

    renderTrigger() {
        return <span></span>;
    }

    render() {
        return <Upload 
        	maxAmount={1} 
        	tips="建议尺寸:640 x 640 像素;您可以拖拽图片调整图片顺序。" 
        	materials
            imgcdn="https://img.yzcdn.cn"
            mediaListUrl="mock/upload-mediaList.json"
        	onSuccess={this.uploadSuccess} />;
    }
}

ReactDOM.render(
    <Simple />
    , mountNode
);

:::

:::demo 上传音频

import Upload from 'zan-upload';

class Simple extends React.Component {
    uploadSuccess(data) {
        console.log(data); // eslint-disable-line
    }

    renderTrigger() {
        return <span></span>;
    }

    render() {
        return <Upload 
            tips="建议尺寸:640 x 640 像素;您可以拖拽图片调整图片顺序。" 
            materials
            type="voice"
            tokenUrl="https://materials.youzan.com/shop/pubAudioUploadToken.json"
            imgcdn="https://img.yzcdn.cn"
            mediaListUrl="mock/upload-mediaList.json"
            onSuccess={this.uploadSuccess} />;
    }
}

ReactDOM.render(
    <Simple />
    , mountNode
);

:::

:::demo 不需要额外传参数,通过tokenUrl修改token

import Upload from 'zan-upload';

class Simple extends React.Component {
    uploadSuccess(data) {
        console.log(data); // eslint-disable-line
    }

    renderTrigger() {
        return <span></span>;
    }

    render() {
        return <Upload 
            maxAmount={1} 
            tips="建议尺寸:640 x 640 像素;您可以拖拽图片调整图片顺序。" 
            materials
            imgcdn="https://img.yzcdn.cn"
            mediaListUrl="mock/upload-mediaList.json"
            onSuccess={this.uploadSuccess} 
            tokenUrl="https://materials.youzan.com/shop/pubImgUploadToken.json" />;
    }
}

ReactDOM.render(
    <Simple />
    , mountNode
);

:::

:::demo 额外传递业务参数,通过onGetToken回调函数修改token

import Upload from 'zan-upload';

class Simple extends React.Component {
    uploadSuccess(data) {
        console.log(data); // eslint-disable-line
    }

    renderTrigger() {
        return <span></span>;
    }

    getTokenHandler() {
        return new Promise(resolve => {
            setTimeout(() => {
                resolve('xxxx');
            }, 100);
        });
    }

    render() {
        return <Upload 
        	maxAmount={1} 
        	tips="建议尺寸:640 x 640 像素;您可以拖拽图片调整图片顺序。" 
        	materials
            imgcdn="https://img.yzcdn.cn"
            mediaListUrl="mock/upload-mediaList.json"
        	onSuccess={this.uploadSuccess} 
        	onGetToken={this.getTokenHandler} />;
    }
}

ReactDOM.render(
    <Simple />
    , mountNode
);

:::

API

参数说明类型默认值是否必填
type上传类型,默认为image,音频上传为voicestring'image'
kdtId店铺idnumber0
prefix前缀命名空间string'rc'
className扩展类名string''
inline是否行内属性booleanfalse
maxSize图片大小限制,单位为bnumber1024 * 1024
maxAmount图片数量限制,0为不限制,1为只支持单文件number0
silent是否开启静默模式,不会提示成功/失败booleanfalse
tips提示文案string''
localOnly是否只支持本地图片booleanfalse
materials是否支持素材银行booleanfalse
imgcdn自定义素材银行图片cdn域名,默认为_global.url.imgqn_string''
categoryId固定categoryId,不显示分组列表anynull
onSuccess上传成功回调,返回的是一个数组functionnoop
onError上传失败回调functionnoop
onProgress上传进度functionnoop
onGetToken自定义获取token回调,需要返回一个promise,如 resolve(token)function内置getToken
filterFiles过滤文件,支持同步和promise的方式functionnoop
accept支持文件类型string'image/gif, image/jpeg, image/png'
scope图片空间名string'kdt_img'
auto是否自动弹出booleanfalse
timeout上传超时毫秒数number60 * 1000
mediaListUrl自定义素材银行列表url [GET]string'//materials.youzan.com/media/mediaList.json'
categoryListUrl自定义素材银行分组列表url [GET]string'//materials.youzan.com/category/categoryList.json'
fetchUrl自定义提取网络图片url [POST]string'//materials.youzan.com/dock/fetch.json'
tokenUrl自定义上传图片token的url [POST]string'//materials.youzan.com/dock/token.json'
uploadUrl自定义上传图片url [POST]string'//upload.qbox.me'
triggerClassName重写trigger样式string'rc-upload-trigger'

FAQs

Package last updated on 07 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc