Angular と RxJS による再開可能なファイルアップロード
ブラウザーが最後の応答を受け取れなかった場合でも、受信側で確定済みのバイト位置から中断した Angular アップロードを再開します。このチュートリアルでは、単一ファイル用の Angular/RxJS フォーム、ローカルの Node.js 受信サーバー、両者を接続するプロキシを作成します。ファイルの公開に成功したら、保存されたファイルを元のファイルと比較できます。
チャンク分割と再開可能なアップロードが必要な理由は?
リクエストが中断して応答がブラウザーに届かなくても、リクエスト自体はサーバーに届いている場合があります。そのため、再開時にはローカルのチャンクカウンターを信用せず、サーバーの確定済みオフセットを読み取ります。この例では 1 MiB のチャンクを順番に送信し、同じページ内での一時停止、再開、キャンセルに対応します。再読み込みすると選択した File と UUID が失われ、受信サーバーを再起動するとセッション状態が失われます。この例では、いずれの場合も以前のアップロードを再開できません。
単一のマルチパートリクエストだけが必要な場合は、基本的な Angular アップロードのチュートリアルを参照してください。ページの再読み込み後も再開できる標準化された方式については、別記事の Angular tus チュートリアルを参照してください。
Angular プロジェクトのセットアップ
Bash、Node.js 24.15.0、Yarn 4.12.0 を備えた Corepack、および最新のブラウザーを使用します。以下では Angular 22.2.0、TypeScript 6.0.3、RxJS 7.8.2 にバージョンを固定します。このブラウザー専用の例は、Linux 上の Node.js 26.8.1 と Chromium 145 でもテスト済みです。バージョンを変更する際は、Angular の互換性要件を確認してください。
任意の親ディレクトリで、次のブロックを貼り付けて実行してください。作成先がすでに存在する場合や、上位に Yarn Plug’n’Play プロジェクトがある場合は処理を拒否します。そのローダーが Angular のビルドに影響する可能性があるためです。いずれかの処理が失敗しても、サブシェルにより現在のディレクトリとシェルオプションは変更されません。
(
node --input-type=module <<'NODE' &&
import { existsSync, realpathSync } from 'node:fs'
import { dirname, join } from 'node:path'
let directory = realpathSync('.')
while (true) {
if (existsSync(join(directory, '.pnp.cjs')) || existsSync(join(directory, '.pnp.js'))) {
console.error('Create this demo outside the enclosing Yarn Plug’n’Play project.')
process.exit(1)
}
const parent = dirname(directory)
if (parent === directory) break
directory = parent
}
NODE
mkdir chunked-upload-app &&
cd chunked-upload-app &&
printf 'nodeLinker: node-modules\nenableGlobalCache: false\n' > .yarnrc.yml &&
touch yarn.lock
)
以下のファイルはすべて chunked-upload-app 内に保存し、エディターで src/app/ を作成してください。package.json で直接依存するパッケージを固定します。インストール時に生成されるロックファイルも保持してください。
{
"name": "chunked-upload-app",
"private": true,
"type": "module",
"packageManager": "yarn@4.12.0",
"scripts": {
"build": "ng build",
"start": "ng serve --host 127.0.0.1 --port 4200"
},
"browserslist": ["Chrome 145"],
"dependencies": {
"@angular/build": "22.2.0",
"@angular/cli": "22.2.0",
"@angular/common": "22.2.0",
"@angular/compiler": "22.2.0",
"@angular/compiler-cli": "22.2.0",
"@angular/core": "22.2.0",
"@angular/platform-browser": "22.2.0",
"rxjs": "7.8.2",
"tslib": "2.8.1",
"typescript": "6.0.3"
}
}
angular.json を保存してください。
{
"version": 1,
"cli": { "analytics": false, "cache": { "enabled": false } },
"projects": {
"demo": {
"projectType": "application",
"root": ".",
"architect": {
"build": {
"builder": "@angular/build:application",
"options": {
"browser": "src/main.ts",
"tsConfig": "tsconfig.json",
"index": "src/index.html",
"outputPath": "dist",
"styles": [],
"assets": []
}
},
"serve": {
"builder": "@angular/build:dev-server",
"options": {
"buildTarget": "demo:build",
"proxyConfig": "proxy.conf.json"
}
}
}
}
}
}
tsconfig.json を保存してください。明示的な .ts インポートはコンパイル時に書き換えられます。
{
"compilerOptions": {
"target": "ES2022",
"module": "preserve",
"moduleResolution": "bundler",
"experimentalDecorators": true,
"strict": true,
"lib": ["ES2022", "DOM"],
"types": [],
"rewriteRelativeImportExtensions": true
},
"angularCompilerOptions": { "strictTemplates": true },
"files": ["src/main.ts"]
}
src/index.html を保存してください。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<base href="/" />
<title>Chunked Angular upload</title>
</head>
<body><app-root></app-root></body>
</html>
proxy.conf.json を保存してください。CLI の Vite ベースのサーバーでネストしたアップロードルートにマッチさせるには、/api/** が必要です。Angular のプロキシ設定を参照してください。ブラウザーでは相対 URL を使うため、リクエストはアプリケーションと同じオリジンに送られます。
{
"/api/**": { "target": "http://127.0.0.1:4317", "secure": false }
}
src/app/app.config.ts を保存してください。Angular のデフォルトの Fetch バックエンドはアップロード進捗を通知しないため、このアプリケーションでは XHR を明示的に選択します。デモ用ヘッダーにより、受信サーバーは通常のクロスサイトフォーム送信を拒否できます。このヘッダーは公開情報であり、認証情報ではありません。
import { provideHttpClient, withInterceptors, withXhr } from '@angular/common/http'
import type { ApplicationConfig } from '@angular/core'
export const appConfig: ApplicationConfig = {
providers: [
provideHttpClient(
withXhr(),
withInterceptors([
(request, next) => next(request.clone({ setHeaders: { 'X-Demo-Upload': '1' } })),
]),
),
],
}
ローカル受信サーバーの追加
receiver.mts を保存してください。これはログインもユーザーごとの所有権管理もない、ループバック用の開発用受信サーバーです。デモ用ヘッダーを持ち、ブラウザーのオリジンが指定されている場合は設定済みのオリジンに一致するリクエストを受け付けます。どのローカルプロセスでもこのヘッダーを送信できるため、このサーバーを外部に公開したり、公開サービスへのプロキシとして使ったりしないでください。
| リクエスト | ローカル受信サーバーの動作 |
|---|---|
PUT /api/uploads/{id} と {size} | セッションを作成するか、UUID とサイズが同じ場合は {offset, complete} を返します。 |
PUT /api/uploads/{id}/bytes | 範囲と本文を検証し、チャンクを書き込んでフラッシュしてから、204 で応答します。 |
POST /api/uploads/{id}/complete | 全バイトが揃っていることを確認し、既存のファイルを置き換えずに uploads/{id}.bin を公開してから、204 を返します。 |
DELETE /api/uploads/{id} | 部分ファイルを削除し、キャンセルマーカーを保持します。公開処理が先に完了した場合は 409 を返します。 |
状態の確認とディスクの変更は、各リクエストの本文を読み取った後、単一プロセス内で同期的に実行します。遅れて届いたチャンクが、キャンセル済みのセッションを再作成することはありません。受け付けるファイルのサイズは 1 バイト以上 100 MiB 以下、各チャンクは最大 1 MiB です。このデモは再起動まで、キャンセル済みと完了済みを含めて最大 32 個の ID を保持します。内容を検査せずに、任意のバイト列を保存します。
import {
closeSync,
fsyncSync,
ftruncateSync,
linkSync,
mkdirSync,
openSync,
rmSync,
statSync,
writeSync,
} from 'node:fs'
import { createServer, type IncomingMessage, type ServerResponse } from 'node:http'
import { resolve } from 'node:path'
type Session = { size: number; offset: number; complete: boolean; canceled: boolean }
class RequestError extends Error {
readonly status: number
constructor(status: number, message: string) {
super(message)
this.status = status
}
}
const maxFile = 100 * 1024 * 1024
const maxChunk = 1024 * 1024
const sessions = new Map<string, Session>()
const directory = resolve('uploads')
const port = Number(process.env.PORT ?? '4317')
const appOrigin = process.env.APP_ORIGIN ?? 'http://127.0.0.1:4200'
if (!Number.isInteger(port) || port < 1 || port > 65535) {
throw new Error('PORT must be between 1 and 65535.')
}
if (new URL(appOrigin).origin !== appOrigin || new URL(appOrigin).hostname !== '127.0.0.1') {
throw new Error('APP_ORIGIN must be a loopback URL such as http://127.0.0.1:4200.')
}
mkdirSync(directory, { recursive: true, mode: 0o700 })
function reply(response: ServerResponse, status: number, value?: unknown): void {
response.writeHead(status, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' })
response.end(value === undefined ? undefined : JSON.stringify(value))
}
async function body(request: IncomingMessage, limit: number): Promise<Buffer> {
const parts: Buffer[] = []
let length = 0
// Keep the socket available for a 413 response when stopping the body reader early.
for await (const part of request.iterator({ destroyOnReturn: false })) {
if (!(part instanceof Buffer)) throw new RequestError(400, 'Expected binary request data.')
length += part.length
if (length > limit) {
request.resume()
throw new RequestError(413, 'Request body is too large.')
}
parts.push(part)
}
return Buffer.concat(parts)
}
function reserve(id: string, size: number): Session {
const existing = sessions.get(id)
if (existing) {
if (existing.canceled) throw new RequestError(410, 'Upload was canceled.')
if (existing.size !== size) throw new RequestError(409, 'Upload size conflicts.')
return existing
}
if (sessions.size >= 32) throw new RequestError(429, 'Restart the demo receiver after 32 IDs.')
const file = openSync(resolve(directory, `${id}.part`), 'wx', 0o600)
closeSync(file)
const session = { size, offset: 0, complete: false, canceled: false }
sessions.set(id, session)
return session
}
async function handle(request: IncomingMessage, response: ServerResponse): Promise<void> {
if (
request.headers['x-demo-upload'] !== '1' ||
(request.headers.origin !== undefined && request.headers.origin !== appOrigin)
) {
throw new RequestError(403, 'Use the local demo application.')
}
const match = /^\/api\/uploads\/([0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})(\/bytes|\/complete)?$/u.exec(request.url ?? '')
if (!match) throw new RequestError(404, 'Unknown upload route.')
const id = match[1]
if (!id) throw new RequestError(400, 'Missing upload ID.')
const operation = match[2] ?? ''
const part = resolve(directory, `${id}.part`)
const output = resolve(directory, `${id}.bin`)
if (request.method === 'PUT' && operation === '') {
let input: unknown
try {
input = JSON.parse((await body(request, 512)).toString('utf8'))
} catch (error) {
if (error instanceof RequestError) throw error
throw new RequestError(400, 'Expected JSON containing size.')
}
if (
typeof input !== 'object' || input === null || !('size' in input) ||
typeof input.size !== 'number' || !Number.isSafeInteger(input.size) ||
input.size < 1 || input.size > maxFile
) {
throw new RequestError(400, 'Choose a file between 1 byte and 100 MiB.')
}
const session = reserve(id, input.size)
reply(response, 200, { offset: session.offset, complete: session.complete })
return
}
// Read first, then recheck state: cancellation can arrive while a body is pending.
const data = await body(request, operation === '/bytes' ? maxChunk : 512)
let session = sessions.get(id)
if (request.method === 'DELETE' && operation === '') {
if (session?.complete) throw new RequestError(409, 'Upload was already published.')
if (!session) {
if (sessions.size >= 32) throw new RequestError(429, 'Restart the demo receiver after 32 IDs.')
session = { size: 0, offset: 0, complete: false, canceled: true }
sessions.set(id, session)
}
session.canceled = true
rmSync(part, { force: true })
reply(response, 204)
return
}
if (!session || session.canceled) throw new RequestError(410, 'Upload is unavailable.')
if (request.method === 'PUT' && operation === '/bytes') {
const range = /^bytes (\d+)-(\d+)\/(\d+)$/u.exec(request.headers['content-range'] ?? '')
if (!range) throw new RequestError(400, 'Expected Content-Range.')
const start = Number(range[1])
const end = Number(range[2]) + 1
const total = Number(range[3])
if (
!Number.isSafeInteger(start) || !Number.isSafeInteger(end) ||
!Number.isSafeInteger(total) || session.complete || start !== session.offset ||
total !== session.size || end <= start || end > total || data.length !== end - start
) {
throw new RequestError(409, 'Range or body does not match the committed offset.')
}
// These synchronous mutations cannot interleave in this single Node process.
const file = openSync(part, 'r+')
try {
let written = 0
while (written < data.length) {
const count = writeSync(file, data, written, data.length - written, start + written)
if (count === 0) throw new Error('Disk write made no progress.')
written += count
}
ftruncateSync(file, end)
fsyncSync(file)
session.offset = end
} finally {
closeSync(file)
}
reply(response, 204)
return
}
if (request.method === 'POST' && operation === '/complete') {
if (!session.complete) {
if (session.offset !== session.size || statSync(part).size !== session.size) {
throw new RequestError(409, 'Upload still has missing bytes.')
}
// A hard link publishes on this filesystem without replacing an existing output.
linkSync(part, output)
session.complete = true
rmSync(part, { force: true })
console.log(`Published uploads/${id}.bin`)
}
reply(response, 204)
return
}
throw new RequestError(405, 'Unsupported upload operation.')
}
const server = createServer((request, response) => {
handle(request, response).catch((error: unknown) => {
if (response.destroyed) return
if (error instanceof RequestError) {
reply(response, error.status, { message: error.message })
return
}
console.error('Receiver could not process the upload.')
reply(response, 500, { message: 'Receiver could not process the upload.' })
})
})
server.requestTimeout = 30_000
server.on('error', () => {
console.error('Receiver failed to listen. Check whether its port is already in use.')
process.exitCode = 1
})
server.listen(port, '127.0.0.1', () => console.log(`Receiver ready on http://127.0.0.1:${port}`))
受信サーバーは、メモリ内のオフセットを進める前に
Node の fsyncSync を呼び出します。これにより、プロセスが稼働している間は応答が失われても再試行できますが、クラッシュからの復旧には対応しません。完成した .bin ファイルは再起動後もディスクに残りますが、セッションのメタデータは残りません。放置された .part ファイルも、受信サーバーを停止して削除するまで残ります。このデモは専用のフォルダーに置いてください。
ファイル分割の実装
以下のサービスは、チャンクを一つずつ切り出します。end は
File.slice では範囲に含まれませんが、範囲ヘッダーでは含まれます。そのため、2,097,155 バイトのファイルの末尾は bytes 2097152-2097154/2097155 になります。短い最終チャンクから合計サイズを推測するわけではありません。
チャンクアップロード用 RxJS パイプラインの作成
サービス全体を src/app/file-upload.service.ts に配置してください。concatMap により、同時に処理中となるリクエストを一つに保ちます。再開のたびに、追加のバイトを送信する前にサーバーの状態を確定します。エラーは引き続き監視でき、選択したファイルも再度の再開に備えて保持されます。
import { HttpClient, HttpEventType } from '@angular/common/http'
import { Injectable, inject } from '@angular/core'
import {
BehaviorSubject,
EMPTY,
Subscription,
catchError,
concatMap,
concatWith,
defer,
finalize,
range,
tap,
} from 'rxjs'
interface UploadState {
progress: number
running: boolean
canceling: boolean
complete: boolean
message: string
}
@Injectable({ providedIn: 'root' })
export class FileUploadService {
readonly state = new BehaviorSubject<UploadState>({
progress: 0,
running: false,
canceling: false,
complete: false,
message: 'Select a file.',
})
readonly #http = inject(HttpClient)
#request = new Subscription()
#file: File | null = null
#id = ''
#offset = 0
readonly #chunkSize = 1024 * 1024
select(file: File): void {
if (this.state.value.canceling) return
this.pause()
this.#file = null
if (file.size === 0 || file.size > 100 * 1024 * 1024) {
this.state.next({
progress: 0,
running: false,
canceling: false,
complete: false,
message: 'Choose a file between 1 byte and 100 MiB.',
})
return
}
this.#file = file
this.#id = crypto.randomUUID()
this.#offset = 0
this.state.next({
progress: 0,
running: false,
canceling: false,
complete: false,
message: 'Ready.',
})
this.resume()
}
resume(): void {
const file = this.#file
if (!file || this.state.value.running || this.state.value.canceling || this.state.value.complete) {
return
}
const url = `/api/uploads/${this.#id}`
this.state.next({ ...this.state.value, running: true, message: 'Uploading…' })
this.#request = this.#http
.put<unknown>(url, { size: file.size }, { timeout: 30_000 })
.pipe(
concatMap((status) => {
if (
typeof status !== 'object' ||
status === null ||
!('offset' in status) ||
typeof status.offset !== 'number' ||
!Number.isSafeInteger(status.offset) ||
status.offset < 0 ||
status.offset > file.size ||
!('complete' in status) ||
typeof status.complete !== 'boolean' ||
(status.complete && status.offset !== file.size)
) {
throw new Error('Invalid upload state')
}
this.#offset = status.offset
this.progress(file)
if (status.complete) {
this.finished()
return EMPTY
}
const offset = status.offset
return range(0, Math.ceil((file.size - offset) / this.#chunkSize)).pipe(
concatMap((index) =>
defer(() => {
const start = offset + index * this.#chunkSize
const end = Math.min(start + this.#chunkSize, file.size)
return this.#http
.put(`${url}/bytes`, file.slice(start, end), {
headers: { 'Content-Range': `bytes ${start}-${end - 1}/${file.size}` },
observe: 'events',
reportProgress: true,
timeout: 30_000,
})
.pipe(
tap((event) => {
if (event.type === HttpEventType.UploadProgress) {
this.progress(file, Math.min(event.loaded, end - start))
}
if (event.type === HttpEventType.Response) {
if (event.status !== 204) throw new Error('Chunk was not committed')
this.#offset = end
this.progress(file)
}
}),
)
}),
),
// Finalization runs once, including when the server already has every byte.
concatWith(
defer(() =>
this.#http
.post(`${url}/complete`, {}, { observe: 'response', timeout: 30_000 })
.pipe(
tap((response) => {
if (response.status !== 204) throw new Error('Publication was not confirmed')
this.finished()
}),
),
),
),
)
}),
finalize(() => this.state.next({ ...this.state.value, running: false })),
)
.subscribe({
error: () =>
this.state.next({ ...this.state.value, message: 'Upload interrupted. Resume to retry.' }),
})
}
pause(): void {
if (this.state.value.canceling) return
this.#request.unsubscribe()
if (this.#file && !this.state.value.complete) {
this.progress(this.#file)
this.state.next({ ...this.state.value, running: false, message: 'Paused.' })
}
}
cancel(): void {
if (this.state.value.canceling) return
this.pause()
if (!this.#file || this.state.value.complete) return
const url = `/api/uploads/${this.#id}`
this.#file = null
let confirmed = false
this.state.next({
progress: 0,
running: true,
canceling: true,
complete: false,
message: 'Canceling…',
})
this.#request = this.#http
.delete(url, { observe: 'response', timeout: 30_000 })
.pipe(
tap((response) => {
if (response.status !== 204) throw new Error('Cancellation was not confirmed')
confirmed = true
}),
// Errors and interrupted requests both leave cleanup unconfirmed.
catchError(() => EMPTY),
// Publish one settled state so observers can safely select another file.
finalize(() =>
this.state.next({
...this.state.value,
running: false,
canceling: false,
message: confirmed ? 'Canceled.' : 'Cancellation unconfirmed. Check your uploads.',
}),
),
)
.subscribe()
}
destroy(): void {
this.pause()
// Destruction also interrupts cleanup; its finalizer reports the unconfirmed result.
this.#request.unsubscribe()
}
private progress(file: File, loaded = 0): void {
this.state.next({
...this.state.value,
progress: Math.min(99, Math.floor((100 * (this.#offset + loaded)) / file.size)),
})
}
private finished(): void {
this.state.next({
progress: 100,
running: false,
canceling: false,
complete: true,
message: 'Upload complete.',
})
}
}
一時停止、再開、キャンセルの追加
購読を解除すると、実行中の HTTP リクエストが中断されます。ただし、サーバーがすでに受け付けたバイトは取り消されません。一時停止では File と UUID をメモリ内に保持し、再開時にオフセットをサーバーの状態と整合させます。再読み込みするとこの状態が失われるため、この例ではページの再読み込みをまたいだ再開はできません。別のファイルを選択する前に、一時停止してください。別のファイルを選択すると新しい UUID が使われ、以前の部分ファイルはディスクに残ります。受信サーバーから削除したい場合は、先にキャンセルしてください。キャンセル時にはサーバー側のクリーンアップを試みます。ネットワーク障害や公開処理との競合が発生した場合は、受信サーバーの出力ディレクトリとログを確認する必要があります。クリーンアップ中は、一時停止、再開、キャンセル、ファイル選択が無効になり、サービスでも無視されます。コンポーネントを破棄するとクリーンアップが中断され、キャンセルは未確認として報告されます。
進捗の追跡
src/app/app.ts を、次のスタンドアロンのルートコンポーネントに置き換えてください。組み込みの制御フロー構文には NgIf が不要です。AsyncPipe は明示的にインポートします。公開が確認されるまで、進捗は 100 未満に留まります。未確認のバイトを再送する必要がある場合、再開時に進捗が戻ることがあります。
import { AsyncPipe } from '@angular/common'
import { Component, inject, OnDestroy } from '@angular/core'
import { FileUploadService } from './file-upload.service.ts'
@Component({
selector: 'app-root',
standalone: true,
imports: [AsyncPipe],
template: `
@if (upload.state | async; as state) {
<label>File <input type="file" (change)="select($event)" [disabled]="state.running" /></label>
<progress aria-label="Upload progress" max="100" [value]="state.progress"></progress>
<p role="status">{{ state.message }}</p>
<button (click)="upload.pause()" [disabled]="!state.running || state.canceling">Pause</button>
<button (click)="upload.resume()" [disabled]="state.running || state.canceling || state.complete">Resume</button>
<button (click)="upload.cancel()" [disabled]="state.canceling || state.complete">Cancel</button>
}
`,
})
export class App implements OnDestroy {
readonly upload = inject(FileUploadService)
select(event: Event): void {
if (!(event.target instanceof HTMLInputElement)) return
const file = event.target.files?.[0]
event.target.value = ''
if (file) this.upload.select(file)
}
ngOnDestroy(): void {
this.upload.destroy()
}
}
src/main.ts を保存して、アプリケーションを起動できるようにしてください。
import { bootstrapApplication } from '@angular/platform-browser'
import { App } from './app/app.ts'
import { appConfig } from './app/app.config.ts'
bootstrapApplication(App, appConfig).catch(() => console.error('Application startup failed.'))
アップロードの実行と検証
すべてのファイルを保存したら、親ディレクトリからインストールとビルドを実行してください。インストールまたはビルドに失敗すると後続の処理は停止し、サブシェルを抜けて元のディレクトリに戻ります。
(
cd chunked-upload-app &&
corepack yarn install &&
corepack yarn build
)
一つ目のターミナルで、同じ親ディレクトリから受信サーバーを起動してください。
(
cd chunked-upload-app &&
node receiver.mts
)
二つ目のターミナルで、Angular 開発サーバーを起動してください。
(
cd chunked-upload-app &&
corepack yarn start
)
http://127.0.0.1:4200 を開き、空ではない 100 MiB 以下のファイルを選択して、状態を確認してください。大きなファイルの転送では、再読み込みせずに Pause、続いて Resume をクリックしてください。クリック前に転送が完了する場合もあります。一時停止する時間を確保したい場合は、ブラウザーのネットワーク速度制限を使用してください。受信サーバーが公開を確認するまで、進捗バーは 100 未満に留まります。その後、ページに Upload complete. が表示され、受信サーバーが
Published uploads/<UUID>.bin を出力します。
チェックサムツールまたはバイト比較を使い、該当する .bin ファイルを選択した入力ファイルと比較してください。UUID は元のファイル名ではなく、受信サーバーのログから取得します。同じ入力ファイルを再度選択すると、別のアップロードが開始されます。コンポーネントは選択後にネイティブの入力要素をクリアするため、change イベントを再度発生させられます。フォアグラウンドで動作する両方のサーバーを Ctrl+C で停止してください。
Upload interrupted. Resume to retry. は、リクエストの失敗、または受信サーバーから無効な状態が返されたことを意味します。受信サーバーが稼働していることと、プロキシがそのポートを指していることを確認してから再開してください。キャンセル時に Cancellation unconfirmed. Check your uploads. と表示された場合は、受信サーバーのログと出力ディレクトリを確認してください。キャンセルが届く前に公開が完了している可能性があります。
デフォルトのポートが使用中の場合は、競合している自分のプロセスを停止するか、空いているポートを二つ選んでください。package.json のフロントエンドポートと proxy.conf.json のバックエンドポートを変更し、対応する PORT と APP_ORIGIN の値を指定して受信サーバーを起動してください。たとえば、プロジェクトディレクトリで PORT=4318 APP_ORIGIN=http://127.0.0.1:4201 node receiver.mts を実行します。プロキシ設定を変更した後は、Angular サーバーを再起動してください。
公開アプリケーションでは、受信 API にも、認証に基づく所有権管理と、変更操作ごとの CSRF 保護の検証が必要です。ここで使うオフセットプロトコルは、どちらも提供しません。標準プロトコルと実績のあるアップロード UI を求める場合は、tus と Uppy を検討してください。
