@koimy/rnw-image-upload
v1.0.5
Published
图片上传
Downloads
2
Readme
图片上传
安装
yarn add @koimy/rnw-image-upload
配置
依赖于 @koimy/rn-image-picker
, 请参考 @koimy/rn-image-picker配置
属性
productid
产品id string 必填
file_url
string 必填
文件服务地址
multiple
number 非必填
是否开启多选,值为文件上限。
files
IFile[] 必填
初始文件
方法
upload()
开始上传
使用示例
import { IFileServer } from '@koimy/rn-file-upload';
import React, { useEffect, useRef, useState } from 'react';
import { Button, Text, View } from 'react-native';
import Upload, { IFile } from './index';
const file_url = '';
const productid = '';
export default () => {
// 图片
const [images, set_images] = useState<IFile[]>([]);
const upload_ref = useRef<{
upload(): IFileServer[]
}>();
/**
* 副作用说明
*/
useEffect(() => {
(async () => {
})();
}, []);
const upload = async () => {
const res = await upload_ref.current!.upload();
set_images(res);
};
return (
<View>
<Text>文件上传</Text>
<Button title='上传' onPress={() => upload()}></Button>
<View style={{ flex: 1 }}>
<Upload ref={upload_ref} multiple={2} file_url={file_url} productid={productid} files={images} />
</View>
</View>
);
};