# @koimy/rn-file-upload

> react-native 上传文件

Latest version **1.0.3** (published 2020-08-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @koimy/rn-file-upload
pnpm add @koimy/rn-file-upload
yarn add @koimy/rn-file-upload
bun add @koimy/rn-file-upload
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2020-08-12 |
| First published | 2020-08-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 10.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | mashizhen |
| Maintainers | dohard |
| Keywords | koimy, cimforce, atom, 原子操作, ai |

## Links

- npm: https://www.npmjs.com/package/@koimy/rn-file-upload
- Repository: http://git.koimy.com/feidao-works/atom-mobile/
- npm.io page: https://npm.io/package/@koimy/rn-file-upload

## Dependencies (2)

- [react-native-fs](https://npm.io/package/react-native-fs.md) ^2.16.6
- [react-native-permissions](https://npm.io/package/react-native-permissions.md) ^2.1.5

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2020-08-12
- 1.0.2 — 2020-08-12

## README

# 文件上传

## 安装

```bash
yarn add @koimy/rn-file-upload
```

## 使用示例

```tsx
import React, { useState } from 'react';
import { Image, Text, TouchableOpacity } from 'react-native';
import image_picker, { ImageData } from '@koimy/rn-image-picker';
import file_upload from './index';

export default () => {

	// 图片
	const [image, set_image] = useState<ImageData>({});
	const file_url = ''
	const productid = ''


	/**
	 * 选取图片
	 */
	const picker = async () => {
		const res = await image_picker({
			multiple: false,
			mediaType: 'photo'
		});
		// 直接渲染本地图片
		// set_image(res[0]);
		if (res.length > 0) {
			const uploads = res.map((item) => {
				return {											// 上传的文件可能为多个，所以是数组
					name: item.path!,								// 上传后的文件名，如果未定义则是filename的文件名
					filename: item.path!,							// 要上传的文件名
					filepath: item.path!,							// 文件的地址
					filetype: item.mime!								// 文件的类型
				};
			});
			const ret = await file_upload(uploads,
				file_url,
				productid,
				(job_id) => {
					console.log(job_id);
				},
				(percentage) => {
					console.log(percentage);
				}
			)
			set_image(ret[0]);
		}
	};


	return (
		<TouchableOpacity style={{ width: '100%', height: '100%' }} onPress={() => picker()}>
			{
				image.path ? (
					<Image resizeMode='cover' style={{ width: '100%', height: '100%' }} source={{ uri: image.filename ? `${file_url}/getfile?productid=${productid}&id=${image.filename}` : image.path }}></Image>
				) : (
						<Text>选择图片</Text>
					)
			}
		</TouchableOpacity>
	);
};

```

---
_Source: https://npm.io/package/@koimy/rn-file-upload · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
