Skip to content

Bug in saving S3 model files #1

@johnnyw-aws

Description

@johnnyw-aws

Describe the bug

Model files from S3 fail to deploy correctly due to issue in init

To Reproduce

  • init against a workspace with GLB model files
  • deploy to a new workspace, attempt to open scene, model file fails to load with red box

Additional context

In the original code, we save the binary buffer to the file [1]

In the latest code, we convert the binary buffer into a UTF-8 string instead of preserving the binary [2]

e.g. confirmed with the following that the results are not the same:

// ts_test.ts
import * as fs from "fs";
import { S3, S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
import { writeFile } from "fs/promises";

const client = new S3Client({ region: "us-east-1" });
const client2 = new S3({ region: "us-east-1" });

const streamToBuffer = (stream: any) =>
  new Promise((resolve, reject) => {
    const chunks: any[] = [];
    stream.on("data", (chunk: any) => chunks.push(chunk));
    stream.on("error", reject);
    stream.on("end", () => resolve(Buffer.concat(chunks)));
  });

async function downloadFile() {
  const command = new GetObjectCommand({
    Bucket: "twinmaker-workspace-silo-261053700147-iad", 
    Key: "20231012_AWSContextModel_NoMaterials_Join_SingleNode.glb"
  });
  
  const data = await client.send(command);

  const bodyContents = await streamToBuffer(data.Body) as Buffer;
  fs.writeFileSync(`/tmp/s3file`, bodyContents);
}


async function downloadFileUtf() {
  const data = await client2.getObject({ 
  Bucket: "twinmaker-workspace-silo-261053700147-iad", 
    Key: "20231012_AWSContextModel_NoMaterials_Join_SingleNode.glb" });
  const bodyContents = (await data.Body?.transformToString('utf-8')) as string;
  fs.writeFileSync(`/tmp/s3file2`, bodyContents);
}

// downloadFile();
downloadFileUtf();

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions