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