Uploading txt file prepends unwanted form data

I’m trying to upload a .txt file through the fileCreate API but I keep getting form data prepended to the body of the file. E.g a file with just “hello world” would have contents of

------formdata-undici-xxContent-Disposition: form-data; name=“content_type”

text/plain------formdata-undici-xxContent-Disposition: form-data; name=“acl”

private------formdata-undici-xxContent-Disposition: form-data; name=“file”; filename=“hello_world.txt”Content-Type: text/plain

hello world

My code looks something like the following.

const dataUrl = `data:text/plain;base64,${Buffer.from(content, 'utf-8').toString('base64')}`;
  
  // Create file using fileCreate mutation with direct content
  const fileCreateMutation = `
    mutation fileCreate($files: [FileCreateInput!]!) {
      fileCreate(files: $files) {
        files {
          ... on GenericFile {
            id
            url
            alt
          }
        }
        userErrors {
          field
          message
        }
      }
    }
  `;
  
  const fileCreationResponse = await adminFetch(fileCreateMutation, {
    variables: {
      files: [{
        alt: fileName,
        contentType: "FILE",
        originalSource: dataUrl,
        filename: fileName
      }]
    }
  });

I’ve tried uploading with staged uploads to no avail either.

Is there a way to just have the file contents in the txt file?

Hey @raiyansayeed,

This is interesting. If you upload the .txt file directly through the store admin do you notice the unwanted form data as well?

The reason I ask is to help narrow down if this is something with the API processing, the file itself or something else.

Nope, the store admin frontend uploads it fine. I’ve worked around the issue by uploading the file with another storage provider (Supabase) and the contents are fine.

Thanks for confirming that workaround. Do you by chance have the x-request-id from the API response headers when you were uploading this? I’d like to see if there’s anything that stands out in our logs that may shine some light on why this is happening.

Hey @raiyansayeed, Are you still experiencing this issue, or can I mark this as solved?