Skip to content

Instantly share code, notes, and snippets.

@jsifalda
Last active December 12, 2025 14:22
Show Gist options
  • Select an option

  • Save jsifalda/85fea660bf2ab4d2b41bc52a37bbb375 to your computer and use it in GitHub Desktop.

Select an option

Save jsifalda/85fea660bf2ab4d2b41bc52a37bbb375 to your computer and use it in GitHub Desktop.
Upload file to UploadThing via their API with N8N
// Javascript CODE n8n node:
const items = $input.all();
const result = [];
for (const item of items) {
const file = item.binary.data;
const name = `${Date.now()}-${file.fileName}`;
// throw new Error(JSON.stringify(file))
const buffer = Buffer.from(file.data, 'base64');
const size = buffer.length;
const type = file.mimeType;
const prepareBody = {
fileType: type,
fileName: name,
fileSize: size,
acl: 'public-read'
};
const prepareData = await this.helpers.httpRequest({
url: 'https://api.uploadthing.com/v7/prepareUpload',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Uploadthing-Api-Key': process.ENV.UPLOADTHING_API_KEY,
'x-uploadthing-fe-package': 'n8n-custom',
'x-uploadthing-version': '7.7.4',
},
body: prepareBody,
json: true, // Ensure JSON parse.
});
// Manual check (if helper doesn't throw).
if (!prepareData || !prepareData.url) {
throw new Error('Prepare failed: Invalid response');
}
result.push(prepareData)
}
return result;
@jsifalda
Copy link
Author

This is how the whole N8N looks like:

SCR-20251212-novb SCR-20251212-nokk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment