App Center File Upload Client
This package, `appcenter-file-upload-client`, provides a client-side JavaScript/TypeScript library designed to streamline the file upload process specifically for Microsoft App Center services. It abstracts the complexities of interacting with the Microsoft file upload service, offering a programmatic interface to upload files with progress tracking, cancellation capabilities, and event hooks for messages and state changes. Currently at version 0.1.0, this package is an early-stage release, and given its last commit date in 2018, it is considered abandoned and unlikely to receive further updates or stability guarantees. Its primary differentiator is its direct integration with App Center's internal file upload mechanisms, requiring `assetId`, `assetDomain`, and `assetToken` values obtained from the App Center service itself.
Common errors
-
TypeError: (0 , appcenter_file_upload_client_1.FileUploadClient) is not a constructor
cause Incorrect import statement, often when mixing CommonJS with ESM or attempting to destructure a default export incorrectly for a named export.fixFor ESM: `import { FileUploadClient } from 'appcenter-file-upload-client';`. For CommonJS: `const { FileUploadClient } = require('appcenter-file-upload-client');`. -
An error occured: Missing required settings: assetId, assetToken, assetDomain (or similar message)
cause The `IFileUploadClientSettings` object passed to the `upload` method is missing one or more critical properties (`assetId`, `assetDomain`, `assetToken`, or `filePath`).fixEnsure all required properties are populated in the settings object, obtaining `assetId`, `assetDomain`, and `assetToken` from the App Center service. -
Upload failed with status 401: Unauthorized (or similar authentication error)
cause The `assetToken` provided is invalid, expired, or does not have the necessary permissions for the upload.fixVerify that the `assetToken` is fresh, correctly obtained from the App Center service, and has appropriate permissions. Check App Center's documentation for token expiry and refresh mechanisms.
Warnings
- breaking This package is at version 0.1.0 and appears to be abandoned since 2018. It is highly unstable, not actively maintained, and any internal changes to the App Center file upload service are unlikely to be reflected or supported by this client. Production use is strongly discouraged.
- gotcha The client requires `assetId`, `assetDomain`, and `assetToken` values that must be securely obtained from the App Center file upload service itself. This library does not handle the acquisition or generation of these authentication tokens.
- gotcha File uploads can be unreliable due to network conditions, server issues, or incorrect authentication. The library provides `onMessage` and `onStateChanged` callbacks, but robust error handling and retry mechanisms need to be implemented externally by the consumer.
Install
-
npm install appcenter-file-upload-client -
yarn add appcenter-file-upload-client -
pnpm add appcenter-file-upload-client
Imports
- FileUploadClient
const FileUploadClient = require('appcenter-file-upload-client');import { FileUploadClient } from 'appcenter-file-upload-client'; - IFileUploadClientSettings
import { IFileUploadClientSettings } from 'appcenter-file-upload-client';import type { IFileUploadClientSettings } from 'appcenter-file-upload-client'; - IProgress
import { IProgress } from 'appcenter-file-upload-client';import type { IProgress } from 'appcenter-file-upload-client';
Quickstart
import { FileUploadClient } from 'appcenter-file-upload-client';
import type { IProgress, MessageLevel, IUploadResults, FileUploadError } from 'appcenter-file-upload-client';
const FILE_PATH = process.env.UPLOAD_FILE_PATH ?? './sample.txt';
// These values must be obtained securely from the App Center Upload Service
// and are required for authentication and targeting the correct upload destination.
const fileUploadData = {
assetId: process.env.APPCENTER_ASSET_ID ?? '',
assetToken: process.env.APPCENTER_ASSET_TOKEN ?? '',
assetUploadDomian: process.env.APPCENTER_ASSET_DOMAIN ?? ''
};
if (!fileUploadData.assetId || !fileUploadData.assetToken || !fileUploadData.assetUploadDomian || !FILE_PATH) {
console.error('Please set UPLOAD_FILE_PATH, APPCENTER_ASSET_ID, APPCENTER_ASSET_TOKEN, and APPCENTER_ASSET_DOMAIN environment variables.');
process.exit(1);
}
new FileUploadClient().upload({
onMessage: (uploadMessage: string, messageLevel: MessageLevel) => {
console.log(`[${MessageLevel[messageLevel]}] Upload message: ${uploadMessage}`);
},
onProgressChanged: (progressData: IProgress) => {
console.log(`Upload progress: ${progressData.percentCompleted}%`);
},
assetId: fileUploadData.assetId,
assetDomain: fileUploadData.assetUploadDomian,
assetToken: fileUploadData.assetToken,
filePath: FILE_PATH,
useLogging: true
}).then((uploadResult: IUploadResults) => {
console.log("File upload completed. Download URL:", uploadResult.downloadUrl);
}).catch((error: FileUploadError) => {
console.error('An error occurred during upload:', error.message);
process.exit(1);
});