Last active
December 12, 2025 14:22
-
-
Save jsifalda/85fea660bf2ab4d2b41bc52a37bbb375 to your computer and use it in GitHub Desktop.
Upload file to UploadThing via their API with N8N
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is how the whole N8N looks like: