diff --git a/web/src/lib/blob-client.ts b/web/src/lib/blob-client.ts index 8b5d1bf..a7f7165 100644 --- a/web/src/lib/blob-client.ts +++ b/web/src/lib/blob-client.ts @@ -16,3 +16,42 @@ export async function getArtifactReadUrl(blobPath: string): Promise { return response.sasUrl; } + +export async function getArtifactUploadUrl(blobPath: string): Promise { + const response = await platformClient.post("/blob/sas", { + container: "attachments", + blobName: blobPath, + permissions: "cw", + expiresInMinutes: 30, + }); + + return response.sasUrl; +} + +export async function uploadArtifact( + file: File, + blobPath: string, +): Promise<{ blobPath: string; contentType: string; sizeBytes: number }> { + const sasUrl = await getArtifactUploadUrl(blobPath); + + await fetch(sasUrl, { + method: "PUT", + headers: { + "x-ms-blob-type": "BlockBlob", + "Content-Type": file.type || "application/octet-stream", + }, + body: file, + }); + + return { + blobPath, + contentType: file.type || "application/octet-stream", + sizeBytes: file.size, + }; +} + +export async function downloadArtifact(blobPath: string): Promise { + const sasUrl = await getArtifactReadUrl(blobPath); + const response = await fetch(sasUrl); + return response.blob(); +}