Skip to content

Commit

Permalink
[libcurl] support uploading large files
Browse files Browse the repository at this point in the history
curl_mime_data requires storing the file in memory
use curl_mime_filename instead of curl_mime_data to support uploading large files.
  • Loading branch information
myml committed Sep 13, 2024
1 parent cd349dc commit 47932bb
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,16 @@ void apiClient_invoke(apiClient_t *apiClient,
memcpy(&fileVar,
keyValuePair->value,
sizeof(fileVar));
curl_mime_data(part,
fileVar->data,
fileVar->len);
curl_mime_filename(part,
"image.png");
if (fileVar->filepath) {
curl_mime_filedata(part, fileVar->filepath);
} else {
curl_mime_data(part, fileVar->data, fileVar->len);
}
if (fileVar->filename) {
curl_mime_filename(part, fileVar->filename);
} else {
curl_mime_filename(part, "image.png");
}
} else {
curl_mime_data(part,
keyValuePair->value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ typedef struct binary_t
{
uint8_t* data;
unsigned int len;
char *filename;
char *filepath;
} binary_t;

binary_t* instantiate_binary_t(char* data, int len);
Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/c-useJsonUnformatted/include/binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ typedef struct binary_t
{
uint8_t* data;
unsigned int len;
char *filename;
char *filepath;
} binary_t;

binary_t* instantiate_binary_t(char* data, int len);
Expand Down
15 changes: 10 additions & 5 deletions samples/client/petstore/c-useJsonUnformatted/src/apiClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,16 @@ void apiClient_invoke(apiClient_t *apiClient,
memcpy(&fileVar,
keyValuePair->value,
sizeof(fileVar));
curl_mime_data(part,
fileVar->data,
fileVar->len);
curl_mime_filename(part,
"image.png");
if (fileVar->filepath) {
curl_mime_filedata(part, fileVar->filepath);
} else {
curl_mime_data(part, fileVar->data, fileVar->len);
}
if (fileVar->filename) {
curl_mime_filename(part, fileVar->filename);
} else {
curl_mime_filename(part, "image.png");
}
} else {
curl_mime_data(part,
keyValuePair->value,
Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/c/include/binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ typedef struct binary_t
{
uint8_t* data;
unsigned int len;
char *filename;
char *filepath;
} binary_t;

binary_t* instantiate_binary_t(char* data, int len);
Expand Down
15 changes: 10 additions & 5 deletions samples/client/petstore/c/src/apiClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,16 @@ void apiClient_invoke(apiClient_t *apiClient,
memcpy(&fileVar,
keyValuePair->value,
sizeof(fileVar));
curl_mime_data(part,
fileVar->data,
fileVar->len);
curl_mime_filename(part,
"image.png");
if (fileVar->filepath) {
curl_mime_filedata(part, fileVar->filepath);
} else {
curl_mime_data(part, fileVar->data, fileVar->len);
}
if (fileVar->filename) {
curl_mime_filename(part, fileVar->filename);
} else {
curl_mime_filename(part, "image.png");
}
} else {
curl_mime_data(part,
keyValuePair->value,
Expand Down

0 comments on commit 47932bb

Please sign in to comment.