# @visionz/upload-helper-react

> ## Getting Started 1. Install package `npm i @visionz/upload-helper-react` 2. Add your API Key to environment variable named `VISIONZ_UPLOAD_API_KEY` * This is equivalent to your password, keep it secret, and **NEVER** expose to the browser 3. (NextJS

Latest version **2.0.3** (published 2024-07-06) · ISC license · 0 weekly downloads

## Install

```sh
npm install @visionz/upload-helper-react
pnpm add @visionz/upload-helper-react
yarn add @visionz/upload-helper-react
bun add @visionz/upload-helper-react
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2024-07-06 |
| First published | 2023-12-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 38.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Simon |
| Maintainers | visionz-admin |
| Keywords | visionz, upload, react |

## Links

- npm: https://www.npmjs.com/package/@visionz/upload-helper-react
- Repository: https://github.com/VisionZ-Tech/upload-helper-react
- Homepage: https://github.com/VisionZ-Tech/upload-helper-react#readme
- Issues: https://github.com/VisionZ-Tech/upload-helper-react/issues
- npm.io page: https://npm.io/package/@visionz/upload-helper-react

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^1.6.3
- [server-only](https://npm.io/package/server-only.md) ^0.0.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.0.3 (latest) — 2024-07-06
- 2.0.2 — 2024-04-06
- 2.0.1 — 2023-12-27
- 2.0.0 — 2023-12-27
- 1.0.7 — 2023-12-26
- 1.0.6 — 2023-12-20
- 1.0.5 — 2023-12-20
- 1.0.4 — 2023-12-20
- 1.0.3 — 2023-12-20
- 1.0.2 — 2023-12-20
- 1.0.1 — 2023-12-20
- 1.0.0 — 2023-12-20

## README

# Welcome to VisionZ Upload Helper (React & Next)

## Getting Started
1. Install package `npm i @visionz/upload-helper-react`
2. Add your API Key to environment variable named `VISIONZ_UPLOAD_API_KEY`
   * This is equivalent to your password, keep it secret, and **NEVER** expose to the browser
3. (NextJS Only) add the following configuration to `next.config.js` file
```javascript
images: {
  domains: ["visionz-upload-07e1217f1104513b7d9dc240b45787b20a9aeadd.s3.us-west-2.amazonaws.com"]
}
```
4. Create a server endpoint for POST method
   * Forward the request body to `visionZUpload` function from `@visionz/upload-helper-react/server`
   * NextJS Sample
```typescript
import { NextRequest, NextResponse } from "next/server";
import { visionZUpload } from "@visionz/upload-helper-react/server";

export async function POST(req: NextRequest) {
  const { status, body } = await visionZUpload(await req.json());
  return NextResponse.json(body, { status });
}
```
5. Use `useVisionZUpload` hook on the client
   * The POST API endpoint created above is the input to the hook
   * NextJS + Mantine FileInput Sample
```tsx
const { onFileChange, uploadSelectedFile, selectedFile } = useVisionZUpload("/api");

return (
  <div>
    <FileInput
      style={{ width: 500 }}
      accept={"image/*"}
      onChange={onFileChange}
      value={selectedFile}
    />
    <button onClick={uploadSelectedFile}>Upload</button>
  </div>
);
```
6. Use `getVisionZFile` function to get URL of an uploaded file from a `uploadId`
   * The POST API endpoint created above is the input to the function
```typescript
const imageSrc = await getVisionZFile("/api", uploadId)
```
7. Use `useVisionZMultipleUpload` hook similar to the singular one
```tsx
const { onFilesChange, uploadSelectedFiles, selectedFiles } = useVisionZMultipleUpload("/api");

return (
  <div>
    <FileInput
      multiple
      style={{ width: 500 }}
      accept={"image/*"}
      onChange={onFilesChange}
      value={selectedFiles}
    />
    <button onClick={uploadSelectedFiles}>Upload</button>
  </div>
);
```
8. Use `getVisionZFiles` function to get URLs of the uploaded files in bulk
   * Recommended to use this function over the singular when fetching more than 1 file
```typescript
const imageSrcs = await getVisionZFiles("/api", uploadIds)
```

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