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?