Overview
Request parameters that correspond to file uploads in multipart requests are typed asio.Reader. The SDK provides flexible options for customizing file names and content types.
Default Behavior
The contents of theio.Reader will by default be sent as a multipart form part with:
- File name:
"anonymous_file" - Content-Type:
"application/octet-stream"
Customizing File Metadata
The file name and content-type can be customized by implementing methods on the run-time type ofio.Reader:
Name() string- for custom file nameContentType() string- for custom content type
os.File implements Name() string, so a file returned by os.Open will be sent with the file name on disk.Using os.File
Helper Function
We provide a helpergcore.File(reader io.Reader, filename string, contentType string) which can be used to wrap any io.Reader with the appropriate file name and content type.
Using gcore.File Helper
Examples
Upload from Memory
Upload JSON Data
Upload Binary Data
The
gcore.File helper accepts any io.Reader, making it flexible for various data sources including files, buffers, streams, and HTTP responses.