How to stream S3 `GetObjectCommandOutput` to Medpl...
# support
n
How would y'all recommend streaming an S3 GetObjectCommandOutput to Medplum's createBinary on the server? The GetObjectCommandOutput.Body is typed as StreamingBlobPayloadOutputTypes which has the method transformToWebStream: () => ReadableStream;, however, the medplum.createBinary call doesn't support this.
I believe this could be resolved (and just generally better support streaming) by extending the createBinary
data
interface like the following
Copy code
diff
diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts
index 85f43b29..d30efd10 100644
--- a/packages/core/src/client.ts
+++ b/packages/core/src/client.ts
@@ -434,7 +434,7 @@ export interface PatchOperation {
 /**
  * Source for a FHIR Binary.
  */
-export type BinarySource = string | File | Blob | Uint8Array;
+export type BinarySource = string | File | Blob | Uint8Array | Readable;
 
 /**
  * Email address definition.
@@ -1885,7 +1885,20 @@ export class MedplumClient extends EventTarget {
       xhr.setRequestHeader('Cache-Control', 'no-cache, no-store, max-age=0');
       xhr.setRequestHeader('Content-Type', contentType);
       xhr.setRequestHeader('X-Medplum', 'extended');
-      xhr.send(data);
+      if (data instanceof Readable) {
+        const writable = new Writeable({
+          write(chunk) {
+            xhr.send(chunk);
+          },
+        });
+
+        data.pipe(writable);
+      } else {
+        xhr.send(data);
+      }
     });
   }
r
Hi @node5585 - that's an interesting proposal! For suggestions like this, I would propose opening a PR. That way, our engineering team can review and provide feedback. Please incldue your exact use case in the description of your PR
n
yup!
r
Great! We'll take a lok