Curl上传文件失败求助:Windows与CentOS环境报错排查
Let’s work through this file upload issue you’re hitting on both Windows and CentOS—error code 26 almost always boils down to curl being unable to locate or access your target file. Here are the most likely fixes, ordered by how common they are:
1. Remove Hidden Special Characters from the File Path
This is the #1 culprit when you copy-paste commands from web pages or documents. Looking at your command, there’s an invisible Unicode character right after the @ symbol (like a left-to-right embed character, U+202A) that’s messing up the path. Curl sees this as part of the filename, so it can’t find your actual file.
Fix:
- Manually retype the entire curl command instead of copying it. Make sure there are no weird invisible characters before the first slash of your path.
- If you want to confirm, paste your command into a text editor that shows invisible characters (like VS Code with the "Render Whitespace" setting enabled) and delete any odd symbols before the path.
2. Verify the File Exists & Is Readable
Double-check that the file actually exists at the path you’re using, and that curl can read it:
- Windows: Open File Explorer and navigate to
C:\Users\lf\Desktop\HQ—confirm theREADMEfile is there. You can also runtype C:\Users\lf\Desktop\HQ\READMEin Command Prompt; if it prints the file content, the file is readable. - CentOS: Run
ls /data/HQ/READMEto confirm the file exists. Then runcat /data/HQ/README—if it outputs the content, the file is readable. Note: Linux is case-sensitive, so make sure the filename matches exactly (e.g.,READMEvsreadmematters).
3. Fix File/Directory Permissions (CentOS)
Even with sudo, if the file or parent directory has restrictive permissions, curl might still fail to access it:
- Check the file permissions with
ls -l /data/HQ/README. Look for the read permission (r) for others (the third set of characters). - If read access is missing, run
chmod +r /data/HQ/READMEto grant read permissions to all users. - Also check the parent directory permissions with
ls -ld /data/HQ—curl needs execute permission (x) on the directory to access files inside it. If missing, runchmod +x /data/HQ.
4. Adjust Windows Path Format (If Needed)
Your Windows path format (/c/Users/...) is valid for the mingw-based curl you’re using, but if you still have issues, try using the native Windows path with quotes:
curl -F "file=@\"C:\Users\lf\Desktop\HQ\README\"" https://example.com/upload
Or use forward slashes without the drive letter prefix (though your original format should work):
curl -F "file=@C:/Users/lf/Desktop/HQ/README" https://example.com/upload
5. Debug with Trace Logs
If none of the above works, generate a debug log to see exactly what curl is trying to do:
- Windows:
curl -F "file=@/c/Users/lf/Desktop/HQ/README" https://example.com/upload --trace-ascii debug.log - CentOS:
curl -F "file=@/data/HQ/README" https://example.com/upload --trace-ascii debug.log
Open debug.log and look for lines related to file opening—they’ll show the exact path curl is trying to access, which can reveal typos or hidden characters you missed.
内容的提问来源于stack exchange,提问作者LF-DevJourney

