CURLOPT_MAXFILESIZE(3)
π CURLOPT_MAXFILESIZE(3) β maximum file size allowed to download π
β¨ NAME β¨
CURLOPT_MAXFILESIZE β maximum file size allowed to download. Yes bestie, straight from the Library Functions Manual, and it's literally giving βknow your download limit before you commitβ energy π
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MAXFILESIZE, long size);
π¦ DESCRIPTION π¦
okay so you pass a long as the parameter, and that number is the maximum accepted size β in bytes β of a file you're willing to download. no cap. If the requested file is found to be larger than this value, the transfer gets aborted and CURLE_FILESIZE_EXCEEDED is returned. π
Passing a zero size disables this whole thing, and passing a negative size yields CURLE_BAD_FUNCTION_ARGUMENT. not me accidentally passing a negative and getting yelled at by libcurl π
β οΈ important vibe check: the file size is not always known prior to the download start, and for such transfers this option has no effect β even if the file transfer eventually ends up being larger than this given limit. literally no effect. iykyk π
If you want a limit above 2GB, use CURLOPT_MAXFILESIZE_LARGE(3) instead, bestie. that's the big-girl option π
Since 8.4.0, this option also stops ongoing transfers if they reach this threshold. periodt. π₯
π DEFAULT π
0, meaning disabled. ngl, that's the default vibe.
π PROTOCOLS π
This functionality affects all supported protocols. all of them. slay β¨
π EXAMPLE π
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
/* refuse to download if larger than 1000 bytes */
curl_easy_setopt(curl, CURLOPT_MAXFILESIZE, 1000L);
result = curl_easy_perform(curl);
}
}
β AVAILABILITY β
Added in curl 7.10.8. vintage but lowkey iconic π
π RETURN VALUE π
curl_easy_setopt(3) returns a CURLcode indicating success or error.
CURLE_OK (0) means everything was OK, non-zero means an error occurred, see libcurl-errors(3). fr fr, check the error code before you spiral π
π«Ά SEE ALSO π«Ά
mwah π this page is from libcurl, dated 2026-10-12, and it's all about CURLOPT_MAXFILESIZE(3) β go set those limits, bestie π§
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms