API リファレンス

アップロード

HTTP でファイルやチャンクをアップロードし、受信済みチャンクの確認、ファイルや添付への結合、処理状況の追跡と削除を行います。

型定義

graphql
type Subscription {
  uploadMergeResult: UploadMergeResult!
}

type Mutation {
  deleteChunks(fileId: String!): Boolean!
  mergeChunks(fileId: String!, totalChunks: Int!, path: String!, replace: Boolean!, totalSize: Long!): MergeTask!
}

type Query {
  mergeStatus(fileId: String!): MergeTask!
  uploadedChunks(fileId: String!): [UploadedChunk!]!
}

scalar Long

type MergeTask {
	status: MergeTaskStatus!
	value: String
	mergedSize: Long
	error: String
}

enum MergeTaskStatus {
	NONE
	STARTED
	MERGING
	DONE
	FAILED
}

type UploadMergeResult {
	fileId: ID!
	ok: Boolean!
	value: String
	mergedSize: Long
	error: String
}

type UploadedChunk {
	index: Int!
	sizeBytes: Long!
}

操作

http

POST /upload

info は POST /upload にバインドした暗号化リクエストエンベロープの生バイト列です。テキストや Base64 ではなく、file より先に送信します。成功時は HTTP 201 と、実際に保存されたファイル名がプレーンテキストで返ります。

bash
curl 'https://<device-host>:<https-port>/upload' \
  -H 'c-id: <client-id>' \
  -F 'info=<./encrypted-info.bin' -F 'file=@./example.txt'
# Send info before file. Metadata JSON: { dir, replace, isAppFile, size }
# info contains raw encrypted request-envelope bytes for POST /upload.
# A Bearer header alone does not authenticate multipart uploads.
http

POST /upload_chunk

POST /upload_chunk 用の暗号化された info の生バイト列を file より先に送信します。成功時は HTTP 201 と index:size がプレーンテキストで返ります。uploadedChunks を確認し、mergeChunks または mergeAppFileChunks を呼び出し、mergeStatus で完了を確認します。

bash
curl 'https://<device-host>:<https-port>/upload_chunk' \
  -H 'c-id: <client-id>' \
  -F 'info=<./encrypted-info.bin' -F 'file=@./chunk.bin'
# Metadata JSON: { fileId, index, size }; bind encryption to POST /upload_chunk.
# Inspect uploadedChunks; call mergeChunks with totalSize for normal files,
# or mergeAppFileChunks for app attachments. Poll mergeStatus for completion.
subscription

uploadMergeResult

非同期のアップロードチャンクマージの完了または失敗情報を受信します。

graphql
subscription uploadMergeResult {
  uploadMergeResult { fileId ok value mergedSize error }
}
mutation

deleteChunks

チャンクアップロードの fileId に対して保存されたすべてのチャンクを削除します。アップロードのキャンセルまたは失敗後に使用し、ディスク領域を解放します。

graphql
mutation deleteChunks($fileId: String!) {
  deleteChunks(fileId: $fileId)
}
mutation

mergeChunks

アップロード済みチャンクを宛先ファイルにマージし始めます。完了は mergeStatus で確認します。

graphql
# Starts the merge and returns immediately; completion arrives over the
# websocket, and `mergeStatus` is the polling fallback for a lost event.
mutation mergeChunks($fileId: String!, $totalChunks: Int!, $path: String!, $replace: Boolean!, $totalSize: Long!) {
  mergeChunks(fileId: $fileId, totalChunks: $totalChunks, path: $path, replace: $replace, totalSize: $totalSize) { status value mergedSize error }
}
query

mergeStatus

アップロードマージの進行状況または失敗を読み取ります。status が NONE の場合、このファイル ID のマージはまだ開始されていません。

graphql
# `NONE` when no merge was ever started for this id, which is what a
# client sees before it calls `mergeChunks`.
query mergeStatus($fileId: String!) {
  mergeStatus(fileId: $fileId) { status value mergedSize error }
}
query

uploadedChunks

再開可能なチャンクアップロードで受信済みのチャンクインデックスを一覧表示します。中断したアップロードの再開に使用します。

graphql
query uploadedChunks($fileId: String!) {
  uploadedChunks(fileId: $fileId) { index sizeBytes }
}