JetBrains Space ヘルプ

ファイルのアップロード

Space は、アップロードされたすべてのファイルの永続的なストレージとして機能します。アプリケーションがファイルを Space にアップロードすると、添付ファイル ID を受け取ります。次に、この ID を使用してファイルを添付したり、課題やメッセージなどにファイルリンクを追加したりできます。Space は、イメージ、ビデオ、テキスト、バイナリファイルなど、すべての基本的なファイル形式をサポートしています。

ファイルのアップロード

ファイルを Space にアップロードするには、アプリケーションは次のエンドポイントに POST リクエストを送信する必要があります。/uploads?name=<filename>&spaceMediaType=<spaceMediaType>

  • filename – (必須) アップロードするファイルの名前。

  • spaceMediaType – (オプション) アップロードされたファイルの使用コンテキスト。指定すると、Space はチャットメッセージや課題など、意図したコンテキストに適したファイルプレビューを生成します。そうでない場合 (または、指定されたコンテキストがファイルが使用される実際のコンテキストと一致しない場合)、ファイルはプレビューなしでそのまま表示されます。可能な値:

    • issue-image-attachment – ファイルは号に添付されたイメージです。

    • chat-image-attachment – ファイルはチャットメッセージに添付されたイメージです。

    • chat-video-attachment – ファイルはチャットメッセージに添付されたビデオです。

  • Content-Type HTTP ヘッダーは必須です。

  • ファイルはリクエスト本文に含めて送信する必要があります。

  • ベアラートークンの認証が必要です。権限はチェックされないため、承認されたクライアントはファイルを Space にアップロードできます。トークンの取得方法を学ぶ

  • 応答で、アプリケーションは添付ファイル ID を含む string を受け取ります。この ID を使用してアップロードされたファイルを参照する方法を学びます

Kotlin Space SDK にはファイルをアップロードするための特定の方法はありません。代わりに、SpaceClient クラスに組み込まれている ktorClient を使用して、アップロードエンドポイントに POST リクエストを送信できます。

val baseClient = HttpClient().config { configureKtorClientForSpace() } // a Space client with the Client Credentials flow authorization val spaceClient = SpaceClient( baseClient, SpaceAppInstance(clientId, clientSecret, spaceUrl), SpaceAuth.ClientCredentials(PermissionScope.fromString("**")) ) // upload a file to Space, return the attachment ID suspend fun uploadFileWithSpaceClient( url: String, fileBytes: ByteArray, fileName: String, spaceMediaType: String ): String { // get token from the authorized client val token = spaceClient.auth.token(spaceClient.ktorClient, spaceClient.appInstance).accessToken // generate the upload URL val uploadUrl = "$url/uploads?name=$fileName&spaceMediaType=$spaceMediaType" // use the ktorClient to send a POST request to the upload URL val uploadSpaceAttachmentResponse = spaceClient.ktorClient.request(uploadUrl) { method = HttpMethod.Post setBody(ByteArrayContent(fileBytes)) header(HttpHeaders.ContentType, getContentType(fileName)) header(HttpHeaders.Authorization, "Bearer $token") } // return the attachment ID return uploadSpaceAttachmentResponse.body<String>() }
POST https://mycompany.jetbrains.space/uploads?name=myphoto.jpg&spaceMediaType=chat-image-attachment Authorization: Bearer access_token_goes_here Content-Type: image/jpeg file_byte_array_data_goes_here

アップロードされたファイルを参照する

アプリケーションがファイルの添付ファイル ID を取得すると、Space 内のファイルを参照できるようになります。

メッセージへの添付ファイル

メッセージを送信するときは、attachments フィールドにその ID を指定して、ファイルを添付ファイルとして追加します。Space では、チャットチャネルやチームメンバーだけでなく、課題、ドキュメント、コードレビュー、コメントをサポートするその他のモジュールにもメッセージを送信できることに注意してください。

spaceClient.chats.messages.sendMessage( channel = ChannelIdentifier.Review(ReviewIdentifier.Id("here_goes_review_id")), content = ChatMessage.Text(text = "Take a look at this image"), attachments = listOf(ImageAttachment( id = "here_goes_attachment_id", width = 100, height = 100 )) )
POST https://mycompany.jetbrains.space/api/http/chats/messages/send-message Authorization: Bearer here_goes_access_token Accept: application/json Content-Type: application/json { "channel": "codeReview:id:here_goes_review_id", "content": { "className": "ChatMessage.Text", "text": "Take a look at this image" }, "attachments": [ { "className": "ImageAttachment", "id": "here_goes_attachment_id", "width": 100, "height": 100 } ] }

デフォルトでは、メッセージの添付ファイルはすべて非公開です。これらは、現在のスコープ内のユーザー (たとえば、現在のチャットチャネルのメンバー) のみが使用できます。添付ファイルを公開するには、getPublicUrl API メソッドを使用します。

spaceClient.uploads.chat.publicUrl.getPublicUrl( channel = ChannelIdentifier.Review(ReviewIdentifier.Id("here_goes_review_id")), message = ChatMessageIdentifier.InternalId("here_goes_message_id"), attachmentId = "here_goes_attachment_id" )
GET https://mycompany.jetbrains.space/api/http/uploads/chat/public-url/codeReview:id:here_goes_review_id/id:here_goes_message_id/here_goes_attachment_id Authorization: Bearer here_goes_access_token Accept: application/json

課題への添付ファイル

課題を作成するときは、attachments フィールドに ID を指定してファイルを添付ファイルとして追加します。

spaceClient.projects.planning.issues.createIssue( project = ProjectIdentifier.Key("MY-PROJECT"), title = "My Issue", status = "Open", attachments = listOf(ImageAttachment( id = "here_goes_attachment_id", width = 100, height = 100 )) )
POST https://mycompany.jetbrains.space/api/http/projects/key:MY-PROJECT/planning/issues Authorization: Bearer here_goes_access_token Accept: application/json Content-Type: application/json { "title": "My Issue", "status": "Open", "attachments": [ { "className": "ImageAttachment", "id": "here_goes_attachment_id", "width": 100, "height": 100 } ] }

既存の課題に添付ファイルを追加することもできます。

spaceClient.projects.planning.issues.attachments.addAttachments( project = ProjectIdentifier.Key("MY-PROJECT"), issueId = IssueIdentifier.Key("MY-PROJECT-T-39"), attachments = listOf(FileAttachment( id = "here_goes_attachment_id", sizeBytes = 1024, filename = "myfile.txt", )) )
POST https://mycompany.jetbrains.space/api/http/projects/key:MY-PROJECT/planning/issues/key:MY-PROJECT-T-39/attachments Authorization: Bearer here_goes_access_token Accept: application/json Content-Type: application/json { "attachments": [ { "className": "FileAttachment", "id": "here_goes_attachment_id", "sizeBytes": 1024, "filename": "myfile.txt" } ] }

Markdown をサポートする Space 内のすべての場所で、ファイルの ID を指定してファイルへのリンクを挿入できます。例: ![image](/d/here_goes_attachment_id) または [download the file]/d/here_goes_attachment_id

添付ファイルが public の場合、その添付ファイルへのリンクを誰とでも共有できます: https://mycompany.jetbrains.space/d/here_goes_attachment_id

関連ページ:

Space での認証

Space のセキュリティは、アクセストークン、つまり API リクエストの認証に使用されるシークレットに基づいています。Space と通信するには、アプリケーションはまずアクセストークンを取得する必要があります。その後、このトークンを使用してリクエストを Space に送信できます。例:GET https://mycompany.jetbrains.space/api/http/absences Authorization: Bearer <here-goes-access-token&...

同期 API

サンプル Sync API を使用したサンプルアプリケーション、Sync API は、アプリケーションが Space 内の特定のエンティティのすべての変更を確実に追跡できるようにする一連のメソッドです。変更を追跡するために、Sync API は etag (エンティティバージョン) を使用します。このアプローチにより、同期の課題 (バグやネットワークエラーなどによる) が防止され、アプリケーションによって取得されるデータが常に最新であり、Space の最新の変更との一貫性が保証されます。Space...

Web フック

サンプル Space Webhook を使用するサンプルアプリケーション、Webhook を使用すると、アプリケーションは Space のイベントに関する通知を受信できるようになります。イベントがトリガーされると、Space は指定されたアプリケーションエンドポイントに POST リクエストを送信します。リクエストには、イベントの詳細を含む JSON ペイロードが含まれています。Space では、Webhook はアプリケーションの不可欠な部分です。各アプリケーションは、独自の構成済み Webho...