In this article, I have covered different examples of CURL file uploa. cURL is a powerful command-line tool used to transfer data to or from a server.
This article discusses one of the many features of cURL: uploading files to a remote server. This process, typically done using the HTTP POST method, is made simple and easily accomplishable with cURL through a few command-line arguments.
Table of Contents
Syntax and Explanation
curl -F "parameter_name=@local_file" URL
- -F: This flag stands for form, allowing you to specify the multipart POST data.
- parameter_name: The name of the form field for file upload.
- @local_file: The local file you wish to upload, preceded by the ‘@’ character.
- URL: The destination URL where the file will be uploaded.
Practical Curl File upload Examples
Example 1: Basic File Upload
curl -F "file=@/path/to/yourfile.png" http://example.com/upload
Example 2: Upload With Custom Field Name
curl -F "myImage=@/path/to/yourfile.jpg" http://example.com/upload
Example 3: Multiple File Upload
curl -F "file1=@/path/to/firstfile.png" -F "file2=@/path/to/secondfile.pdf" http://example.com/upload
Example 4: Upload With Different Form Fields
curl -F "image=@/path/to/image.png" -F "description=Profile picture" http://example.com/upload
Example 5: Authentication With File Upload
curl -u username:password -F "file=@/path/to/securefile.zip" http://example.com/upload
Conclusive Summary
References
- cURL official documentation: https://curl.haxx.se/docs/
- HTTP specifications and multipart/form-data: https://tools.ietf.org/html/rfc7578