@welshare/sdk
    Preparing search index...

    Function fetchS3WriteDelegation

    • Fetch a presigned URL for uploading encrypted files to S3 storage.

      Parameters

      • keypair: SessionKeypair

        The user's session keypair for authentication

      • metadata: WriteMetadata

        File metadata including reference, fileName, and fileType

      • environment: WelshareApiEnvironment

        The Welshare API environment configuration

      Returns Promise<WriteDelegationResponse>

      Promise containing presignedUrl (S3 PUT URL) and uploadKey (storage path)

      import { WelshareApi, resolveEnvironment } from "@welshare/sdk";

      const environment = resolveEnvironment("production");
      const { presignedUrl, uploadKey } = await WelshareApi.fetchS3WriteDelegation(
      keypair,
      {
      reference: "questionnaire/abc-123/photo",
      fileName: "photo.jpg",
      fileType: "image/jpeg",
      },
      environment
      );

      // Upload encrypted file to S3
      await fetch(presignedUrl, {
      method: "PUT",
      body: encryptedFileData,
      headers: { "Content-Type": "application/octet-stream" },
      });

      Side effects:

      • Makes HTTP POST to {apiUrl}/auth/delegate/storage?requestType=write
      • Creates a self-signed JWT using the keypair for authentication

      Security notes:

      • Presigned URLs expire after 15 seconds
      • The uploadKey format: {network}/user-uploads/{did}/{timestamp}-{fileName}