mdwiltfong / doc-inspector

1 stars 0 forks source link

Document Upload API Endpoint #7

Closed Jamesllllllllll closed 11 months ago

Jamesllllllllll commented 11 months ago

I'm looking at /routes/document/POST.js

This passes the file along to /document/actions/create however I don't see the actual file object:

const { name, description, role, assistantId } = request.body; // [James] Should file be here?
  const data = {
    name,
    role,
    assistantId,
  };
  console.log(data);

  const fileContents = JSON.stringify(data);
  const bufferedContent = Buffer.from(fileContents).toString("base64");
  console.log("buffered Content", bufferedContent);
  const newDocument = await api.document.create({
    file: {
      // set the filename
      fileName: data.name,
      // base64 encode the file contents to pass to Gadget
      base64: bufferedContent,
    },
    role: data.role,
    assistant: {
      _link: data.assistantId,
    },
  });

Does this just create a string of the name, role and assistantId from the body of the request? I might be missing where the file is here.

Right now on the Front End I'm directly calling api.document.create and it correctly adds records. When I get the return value, I can pass the file's id to the /routes/assistants POST request and include an array of file ids for the creation of the assistant.

mdwiltfong commented 11 months ago

I am not 100%, but I don't think the gadget api client calls this route. I mainly had this route up for testing. How are you currently uploading documents?

mdwiltfong commented 11 months ago

We've concluded that the api client being used in the frontend bypasses the HTTP route. We keep the HTTP route to test nonetheless.