2.1.5 • Published 3 years ago

bee-upload v2.1.5

Weekly downloads
122
License
MIT
Repository
github
Last release
3 years ago

bee-upload

npm version Build Status devDependency Status

通过Upload可以将资源(web page,text,picture,video...)传到远程服务器

使用

使用单独的Upload包

组件引入

先进行下载Upload包

npm install --save bee-upload

组件调用

import { Upload } from 'bee-upload';

const props = {
  name: 'file',
  action: '/upload.do',
  headers: {
    authorization: 'authorization-text',
  },
  onChange(info) {
    if (info.file.status !== 'uploading') {
      console.log(info.file, info.fileList);
    }
    if (info.file.status === 'done') {
      console.log(`${info.file.name} file uploaded successfully`);
    } else if (info.file.status === 'error') {
      console.log(`${info.file.name} file upload failed.`);
    }
  },
};

class Demo1 extends Component {
	render(){
		return( 
			<Upload {...props}>
        <Button type="primary" shape="border">
          <Icon type="upload" /> Click to Upload
        </Button>
      </Upload>
		)
	}
}

React.render(<Demo1 />, document.getElementById('target'));

样式引入

  • 可以使用link引入dist目录下upload.css
<link rel="stylesheet" href="./node_modules/build/bee-upload.css">
  • 可以在js中import样式
import "./node_modules/src/Upload.scss"
//或是
import "./node_modules/build/bee-upload.css"

API

参数说明类型默认值
name文件名stringfile
defaultFileList默认已上传的文件列表array-
fileList已上传的文件列表,多用于onChange事件里array-
action上传的服务器地址array-
data上传参数或者函数Object or function-
size上传文件的大小限制单位是bytenumber1024000
headers设置请求的头部信息 兼容ie10以上object-
showUploadList是否显示上传列表booltrue
multiple是否支持多文件上传 兼容ie10以上boolfalse
accept设置文件接收类型string-
beforeUpload在上传之前执行的函数,当Promise返回false或者被拒绝,函数被中指。不兼容老iefunc-
customRequest覆盖默认的XHR,可定制自己的XMLHttpRequestfunc-
onChange当上传状态改变之后执行的回调函数func-
onPreview点击预览时执行的回调方法,参数为当前点击的上传文件对象,若要阻止默认预览需return falsefunc-
preventDefaultPreview点击预览时,如果要阻止默认预览请设置为true,默认值为falsefunc-
listType内置的样式,支持text和picturestring'text'
onRemove当删除按钮点击后触发的回调函数func-
supportServerRender当服务器正在渲染时,是否需要打开boolfalse

onChange

当文件正在上传,上传成功和上传失败触发的回调函数。 当上传状态发生变化,返回下列参数。

{
  file: {
	   uid: 'uid',      // 唯一性id
	   name: 'xx.png'   // 文件名
	   status: 'done',  // 参数:uploading, done, error, removed
	   response: '{"status": "success"}',  // 服务器返回的参数
	},
  fileList: [ /* ... */ ], //当前文件列表
  event: { /* ... */ }, //服务器响应:包括上传进度  不兼容老的浏览器
}

IE兼容

IE8/9 Note

下载弹出窗口问题

使用iframe方式上传时,响应response的content-type应该是 text/plain或者 text/html.referense

此外,在iframe模式下,响应的状态应始终为200 OK,否则可能会在IE 8/9中获得Access被拒绝的错误。

域问题

如果页面设置document.domain,则服务器应根据_documentDomain参数输出document.domain

var ret = '';
if (postData._documentDomain) {
  ret += '<script>document.domain="'+postData._documentDomain+'";</script>';
}
this.body = ret + '{"url":"xx.jpq"}';

开发调试

$ git clone https://github.com/tinper-bee/bee-upload
$ cd bee-upload
$ npm install
$ npm run dev
2.1.5

3 years ago

2.1.4

3 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

5 years ago

2.0.5-alpha.2

5 years ago

2.0.5-alpha.1

5 years ago

2.0.5-alpha.0

5 years ago

2.0.4

5 years ago

2.0.4-alpha.0

5 years ago

2.0.3

5 years ago

2.0.3-alpha.0

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.1-alhpa.2

5 years ago

2.0.1-alpha.1

5 years ago

2.0.1-alpha.0

5 years ago

2.0.0

5 years ago

1.1.0

5 years ago

1.1.0-alpha.0

5 years ago

1.0.0

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago