# appcenter-file-upload-client

> Upload client for App Center services

Latest version **0.1.0** (published 2023-01-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install appcenter-file-upload-client
pnpm add appcenter-file-upload-client
yarn add appcenter-file-upload-client
bun add appcenter-file-upload-client
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2023-01-13 |
| First published | 2017-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 60.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Microsoft |
| Maintainers | sergey-akhalkov, max-mironov, appcenter, stdover, turanuk, jphenow, jacobroberts |

## Links

- npm: https://www.npmjs.com/package/appcenter-file-upload-client
- Repository: https://github.com/Microsoft/appcenter-file-upload-client
- Homepage: https://github.com/Microsoft/appcenter-file-upload-client#readme
- Issues: https://github.com/Microsoft/appcenter-file-upload-client/issues
- npm.io page: https://npm.io/package/appcenter-file-upload-client

## Dependencies (3)

- [url-parse](https://npm.io/package/url-parse.md) ^1.4.7
- [superagent](https://npm.io/package/superagent.md) 5.1.0
- [detect-node](https://npm.io/package/detect-node.md) ^2.0.4

## Recent versions

- 0.1.0 (latest) — 2023-01-13
- 0.0.24 — 2020-01-10
- 0.0.23 — 2019-12-18
- 0.0.22 — 2019-10-16
- 0.0.21 — 2019-10-11
- 0.0.20 — 2019-10-11
- 0.0.19 — 2019-10-10
- 0.0.18 — 2019-10-10
- 0.0.17 — 2019-10-10
- 0.0.16 — 2019-10-10
- 0.0.15 — 2019-10-10
- 0.0.14 — 2019-10-10
- 0.0.13 — 2019-10-10
- 0.0.12 — 2019-10-10
- 0.0.11 — 2019-10-10
- … 9 more at https://npm.io/package/appcenter-file-upload-client/versions

## README

## `FileUploadClient` - client to simplify upload process for AppCenter needs using Microsoft file upload service 

## Build
1. `npm install`
2. `npm run build`

## Scripts

There are a bunch of scripts in package.json file. Here's what they are and what they do:

| Script command | What it does |
|----------------|------------- |
| `npm run build` | Compiles the typescript into javascript, creates `dist` directory. |
| `npm run clean` | Cleans up any compilation output. |
| `npm run prepublish` | Clean dist folder, compiles ts and moves js to dist folder.  |

There will be more over time.

## Publish package updates to npm

If you don't already have a user account in npm, go to your terminal and type in `npm adduser` and follow the instructions to create an account.

Go to `npmjs.com/package/appcenter-file-upload-client` to view the list of admins.

Ask one of the current admins to add you to the package as an admin in npm.

**Wait 30 minutes** after getting added to the package and then go to your terminal and type. 

`npm run prepublish`

`npm publish`

If you have auth issues when running these commands type `npm login` in your terminal and follow the instructions to log in.

## JavaScript API Reference

After importing, `file-upload-client` module could be used by calling `upload` method, accepting the following object:

```javascript
interface IFileUploadClientSettings {
  assetId: string;
  assetDomain: string;
  assetToken: string;
  filePath: string;
  useLogging?: boolean;

  onProgressChanged?(progress: IProgress): void;
  onMessage?(errorMessage: string, MessageLevel: MessageLevel): void;
  onStateChanged?(status: FileUploadServiceState): void;
}
```
*NOTE: assetId/assetDomain/assetToken should be provided by File Upload Service.*

The upload events adds useful hooks to track upload process.

### **File Upload client** public methods avaliable:

* [upload]: Uploads file by providing relevant information fetched from Upload Service:

```javascript
const fileUploadData = {
  assetId: "",
  assetToken: "",
  assetUploadDomian: ""
};
```

Example Usage:

```javascript
new FileUploadClient().upload(<IFileUploadClientSettings>{
  onMessage: (uploadMessage: string, messageLevel: MessageLevel) => {
    console.log(`Upload message:  ${uploadMessage}`);
  },
  onProgressChanged: (progressData: IProgress) => {
    console.log(`Upload progress: ${progressData.percentCompleted}`);
  },
  assetId: fileUploadData.assetId,
  assetDomain: fileUploadData.assetUploadDomian,
  assetToken: fileUploadData.assetToken,
  filePath: FILE_PATH
}).then((uploadResult: IUploadResults) => {
  console.log("Wow, upload completed, use this URL to download file: ", uploadResult.downloadUrl);
}).catch((error: FileUploadError) => {
  console.log('An error occured: ', error.message);
});
```

* [cancel]: Cancel current upload:

Example Usage:

```javascript
const uploadClient = new FileUploadClient({ ... });
uploadClient.upload( { ... });
uploadClient.cancel();
```

* [isUploadInProgress]: Check if upload is already in progress:

Example Usage:

```javascript
const uploadClient = new FileUploadClient({ ... });
const isInProgress = uploadClient.isUploadInProgress();
```

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