1. Opening Problem Statement
Meet Somchai, a customer support agent handling hundreds of file attachments daily sent through the LINE Messaging app. Each file, whether image, audio, or video, needs to be saved securely in Google Drive, organized by date and file type, and documented for easy retrieval. Currently, Somchai spends over two hours daily manually downloading, organizing, and logging these files. This tedious process leads to risks like misplaced files, inconsistent naming, and delayed response to customers who request confirmation of their uploads.
Somchai’s manual workflow not only wastes time but also increases the chance of errors and customer dissatisfaction. What if there was a solution to automate this entire process seamlessly, ensuring Somchai spends less time on repetitive tasks and more on meaningful customer interaction?
2. What This Automation Does
This specific n8n workflow listens for incoming file messages from LINE Messaging API and performs the following precise tasks:
- Auto-downloads the file content sent via LINE in real time.
- Validates the file type against a predefined allowed list stored in Google Sheets.
- Manages Google Drive folders by optionally creating and using date and/or file type-based subfolders for organized storage.
- Uploads files to the correct Google Drive folder based on dynamic folder paths.
- Logs file details including name, upload timestamp, file type, and Google Drive URL into a centralized Google Sheet.
- Optionally replies to the LINE user with the file URL or an error message if the file type is disallowed.
By automating these tasks, the workflow eliminates hours of repetitive work each day, minimizes human errors, ensures consistent file organization, and improves user communication with instant feedback.
3. Prerequisites ⚙️
- n8n account (cloud or self-hosted). For self-hosting, consider options like Hostinger’s n8n hosting.
- Google Sheets account with access and API credentials configured in n8n.
- Google Drive account with required API access and permission for n8n OAuth2 integrations.
- LINE Messaging API channel set up with webhook URL pointing to n8n’s endpoint.
- HTTP Header Authentication credential for LINE API access (Channel access token).
4. Step-by-Step Guide ✏️
Step 1: Set up LINE Webhook Listener node
Navigate to the n8n editor and add a Webhook node named LINE Webhook Listener. Configure the path as line-webhook and set HTTP method to POST. This node listens for incoming file message events from LINE.
Once configured, copy the webhook URL and set it as the webhook URL in your LINE Messaging channel settings.
You should see JSON payloads arriving when triggered by LINE file sends.
Common mistake: Not updating the webhook URL on LINE’s developer console will prevent trigger firing.
Step 2: Configure Google Sheets “Get Config” node
Add a Google Sheets node named Get Config. Set the sheet ID to your configuration sheet and range to config!A1:H2, where you store parameters like allowed file types, parent folder ID, and flags for storing by date or file type.
Authorize with your Google Sheets OAuth2 credential.
This node fetches config on each workflow trigger to keep automation dynamic.
Step 3: Merge event data with configuration data
Add a Merge node named Merge Event and Config Data set to mergeByIndex. Connect the webhook and Get Config nodes to this merge node. This combines file event info with your config settings.
Step 4: Use a Code node to determine base folder info
Add a Code node called Determine Folder Info. Paste the following JavaScript code:
const data = items[0].json;
const config = data.config;
const event = data.event;
let baseFolderId = config["Parent Folder ID"];
let dateFolderName = "";
let fileTypeFolderName = "";
if (config["Store by Date"]) {
dateFolderName = config["CurrentDate"] ? config["CurrentDate"] : new Date().toISOString().slice(0,10).replace(/-/g, "");
}
if (config["Store by File Type"]) {
if (event.body && event.body.events && event.body.events.length > 0) {
fileTypeFolderName = event.body.events[0].message.type.toLowerCase();
}
}
return [{ json: { baseFolderId, dateFolderName, fileTypeFolderName, storeByDate: config["Store by Date"], storeByFileType: config["Store by File Type"], event: event, config: config } }];
This node outputs the folder names and IDs needed to locate or create the target folders.
Step 5: Search or create date folder
Use a Google Drive node with resource fileFolder and query the dateFolderName inside the baseFolderId. Connect to an If node checking if the folder was found.
If no folder exists, add another Google Drive node to create the folder with the dateFolderName inside the base folder.
Use a Code node to set the ID for next steps, picking the existing or newly created folder ID.
Step 6: Search or create file type folder
Similarly, query Google Drive for the fileTypeFolderName folder inside the date folder or base folder depending on your config.
If it doesn’t exist, create it with a Google Drive node.
Set the folder ID with a Code node, just like the date folder step.
Step 7: Determine the final parent folder ID
Use a Code node named Configure Final Parent Folder ID to decide the ultimate upload folder ID based on your config flags for storing by date, file type, both, or neither.
Example code logic snippet:
const config = $('Get Config').first().json;
let finalParentId = '';
if (config["Store by Date"] && config["Store by File Type"]) {
finalParentId = $('Set File Type Folder ID').first().json.targetParentId;
} else if (config["Store by Date"]) {
finalParentId = $('Set Date Folder ID').first().json.targetParentId;
} else if (config["Store by File Type"]) {
finalParentId = $('Set File Type Folder ID').first().json.targetParentId;
} else {
finalParentId = config["Parent Folder ID"];
}
items[0].json.finalParentId = finalParentId;
return [items[0]];
Step 8: Download file binary content from LINE API
Add an HTTP Request node named Get File Binary Content. Configure URL with the LINE message ID to fetch the binary content (image, video, audio).
Use HTTP header authentication with your LINE channel access token for authorization.
Step 9: Validate file type
Add a Code node called Validate File Type to check if the file type sent by LINE is among the allowed types fetched from Google Sheets config.
Throw an error if the type is disallowed, which halts upload but triggers a reply message node.
Step 10: Upload file to Google Drive
Add a Google Drive node Upload File to Google Drive to upload the validated file to the computed final folder ID path. Use the timestamp for the filename.
Step 11: Log file details to Google Sheets
Add a Google Sheets node Log File Details to Google Sheet to append a new row with file metadata: file name, type, upload date, and clickable Google Drive URL.
Step 12: Send LINE Reply message if enabled
Add an If node Check Reply Enabled Flag that reads config flag whether to reply back to LINE. If true, an HTTP Request node Send LINE Reply Message sends a message including either the upload URL or validation error message.
5. Customizations ✏️
- Change storage organization: In the Get Config Google Sheet, toggle
Store by DateorStore by File Typeflags to reorganize folder structure dynamically. - Modify allowed file types: Update the
Allow File Typescolumn in the config sheet with pipe-separated MIME types likeimage/jpeg|video/mp4. The Validate File Type node automatically respects changes. - Customize reply messages: Edit the payload in Send LINE Reply Message node JSON body to return custom texts or even add multiple message types like stickers or images.
- Change folder naming format: Modify the Determine Folder Info Code node to alter the date format or folder naming conventions.
- Disable reply functionality: Set
Reply Enabledin config Google Sheets to false to turn off automatic LINE replies for silent uploads.
6. Troubleshooting 🔧
- Problem: “File type ‘xyz’ is not allowed.”
Cause: The incoming file type is not listed in the config’s allowed file types.
Solution: Update the Allow File Types cell in the Google Sheet to include the new type or fix the incoming file’s MIME type. - Problem: “No input items” in Code node logs.
Cause: Some branch conditions fail and return empty datasets.
Solution: Verify upstream IF nodes logic and ensure correct connections are active. - Problem: Google Drive folder not found or not created.
Cause: Parent folder ID incorrect or missing Google Drive API permissions.
Solution: Confirm parent folder ID in the config sheet and OAuth scope permissions. - Problem: LINE reply messages not received.
Cause: ‘Reply Enabled’ flag is false or incorrect channel token.
Solution: Check config flag and ensure HTTP header auth credentials are correct and active.
7. Pre-Production Checklist ✅
- Test the LINE webhook endpoint with sample file messages.
- Confirm Google Sheets config data matches expected structure and credentials are authorized.
- Validate Google Drive folder IDs and API permissions.
- Test different file types to ensure the Validate File Type node works as expected.
- Verify that reply flag triggers LINE message replies properly.
- Backup Google Sheet before huge batch logging for rollback.
8. Deployment Guide
Activate your workflow in n8n by toggling the activation switch in the top right. Ensure your webhook is publicly accessible for LINE to reach it.
Monitor the workflow’s executions from n8n’s dashboard to catch any failures. Use logs to debug.
Optionally, set up error notifications via email or Slack for proactive handling.
10. Conclusion
You’ve just automated the tedious task of saving LINE file messages to Google Drive with organized folder structures and logging using Google Sheets. This workflow can save Somchai over two hours daily, drastically reduce errors, and improve response quality by sending instant upload confirmations.
Next, consider automating customer notification about file status with Slack, integrating with CRM tools for richer data, or adding AI-based image/video processing steps post-upload.
Start building this workflow with n8n today and transform your file handling process!