CURLOPT_MAXFILESIZE.md (1716B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_MAXFILESIZE 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_MAXFILESIZE_LARGE (3) 9 - CURLOPT_MAX_RECV_SPEED_LARGE (3) 10 Protocol: 11 - All 12 Added-in: 7.10.8 13 --- 14 15 # NAME 16 17 CURLOPT_MAXFILESIZE - maximum file size allowed to download 18 19 # SYNOPSIS 20 21 ~~~c 22 #include <curl/curl.h> 23 24 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MAXFILESIZE, long size); 25 ~~~ 26 27 # DESCRIPTION 28 29 Pass a long as parameter. This specifies the maximum accepted *size* (in 30 bytes) of a file to download. If the file requested is found larger than this 31 value, the transfer is aborted and *CURLE_FILESIZE_EXCEEDED* is returned. 32 Passing a zero *size* disables this, and passing a negative *size* yields a 33 *CURLE_BAD_FUNCTION_ARGUMENT*. 34 35 The file size is not always known prior to the download start, and for such 36 transfers this option has no effect - even if the file transfer eventually 37 ends up being larger than this given limit. 38 39 If you want a limit above 2GB, use CURLOPT_MAXFILESIZE_LARGE(3). 40 41 Since 8.4.0, this option also stops ongoing transfers if they reach this 42 threshold. 43 44 # DEFAULT 45 46 0, meaning disabled. 47 48 # %PROTOCOLS% 49 50 # EXAMPLE 51 52 ~~~c 53 int main(void) 54 { 55 CURL *curl = curl_easy_init(); 56 if(curl) { 57 CURLcode ret; 58 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/"); 59 /* refuse to download if larger than 1000 bytes */ 60 curl_easy_setopt(curl, CURLOPT_MAXFILESIZE, 1000L); 61 ret = curl_easy_perform(curl); 62 } 63 } 64 ~~~ 65 66 # %AVAILABILITY% 67 68 # RETURN VALUE 69 70 curl_easy_setopt(3) returns a CURLcode indicating success or error. 71 72 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 73 libcurl-errors(3).