Overview
Some applications may throw an error when uploading a file that contains multiple dots in the filename (e.g., example.file.name.zip). This can cause the upload step to fail. This document outlines a workaround to rename the file after it has been downloaded but before it is uploaded.
Limitation
Files downloaded to the Functionize execution VM cannot be renamed directly using file system operations before the upload step.
Recommended Approach
Rename After Download Using JavaScript
To work around this limitation, use a JavaScript action that allows the file to be re-downloaded with a corrected filename.
This approach does not require any application-side changes.
Solution Overview
The workaround follows these steps:
- Allow the application to download the file normally.
- Execute a JavaScript snippet that:
- Injects a temporary Choose File input on the page
- Allows the user/test to select the already downloaded file
- Renames the file by removing the extra dot
- Re-downloads the file with the corrected filename
- Use the renamed file in the upload step.
Implementation Steps
- Add a JavaScript Action immediately after the download step.
- Paste and execute the JavaScript snippet below.
- Select the originally downloaded file when prompted.
- Use the newly downloaded (renamed) file in the upload step.
JavaScript Snippet
(function() {
// Create file input
const input = document.createElement('input');
input.type = 'file';
// Position at bottom-left
input.style.position = 'fixed';
input.style.left = '20px';
input.style.bottom = '20px';
input.style.zIndex = '9999';
input.onchange = () => {
const file = input.files[0];
if (!file) return;
let fileName = file.name;
// Rename file by removing extra dots before extension
const parts = fileName.split('.');
if (parts.length > 2) {
const base = parts[0];
const middle = parts.slice(1, -1).join('');
const ext = parts[parts.length - 1];
fileName = base + middle + '.' + ext;
}
// Re-download file with renamed filename
const a = document.createElement('a');
a.href = window.URL.createObjectURL(file);
a.download = fileName;
a.click();
};
document.body.appendChild(input);
})();
Outcome
- File is renamed after download and before upload
- Upload step completes without errors
- No application-side changes required
Best Practices
- Use this approach only when filename issues cannot be resolved at the application level.
- Keep JavaScript actions isolated and clearly documented in the test.
- Validate the renamed file before proceeding with the upload step.
- Use consistent naming conventions to avoid similar issues in future tests.
Related Articles
- Using JavaScript Actions in Functionize
- Handling File Uploads in Functionize
- Troubleshooting File Download Issues
Summary
When direct file renaming is not supported on the execution VM, a JavaScript-based re-download approach provides a reliable workaround. This method enables tests to proceed without errors caused by invalid filenames and avoids the need for application changes.