Artifactspublic-v0

curl

master
ply4 git calls38 ms288 KiB2 cachedprotocol v2
99 lines2.6 KiBRaw

NAME

curl_mime_filedata - set a mime part's body data from a file contents

SYNOPSIS

c
#include <curl/curl.h>

CURLcode curl_mime_filedata(curl_mimepart *part,
                            const char *filename);

DESCRIPTION

curl_mime_filedata(3) sets a mime part's body content from the named file's contents. This is an alternative to curl_mime_data(3) for setting data to a mime part.

part is the part's to assign contents to.

filename points to the null-terminated file's path name. The pointer can be NULL to detach the previous part contents settings. Filename storage can be safely be reused after this call.

As a side effect, the part's remote filename is set to the base name of the given filename if it is a valid named file. This can be undone or overridden by a subsequent call to curl_mime_filename(3).

The contents of the file is read during the file transfer in a streaming manner to allow huge files to get transferred without using much memory. It therefore requires that the file is kept intact during the entire request.

If the file size cannot be determined before actually reading it (such as for a character device or named pipe), the whole mime structure containing the part is transferred using chunks by HTTP but is rejected by IMAP.

Setting a part's contents multiple times is valid: only the value set by the last call is retained.

%PROTOCOLS%

EXAMPLE

c
int main(void)
{
  curl_mime *mime;
  curl_mimepart *part;

  CURL *curl = curl_easy_init();
  if(curl) {
    /* create a mime handle */
    mime = curl_mime_init(curl);

    /* add a part */
    part = curl_mime_addpart(mime);

    /* send data from this file */
    curl_mime_filedata(part, "image.png");

    /* set name */
    curl_mime_name(part, "data");
  }
}

%AVAILABILITY%

RETURN VALUE

This function returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK, non-zero means an error occurred, see libcurl-errors(3). If CURLOPT_ERRORBUFFER(3) was set with curl_easy_setopt(3) there can be an error message stored in the error buffer when non-zero is returned.

CURLE_READ_ERROR is only an indication that the file is not yet readable: it can be safely ignored at this time, but the file must be made readable before the pertaining easy handle is performed.

1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_mime_filedata
5Section: 3
6Source: libcurl
7See-also:
8 - curl_mime_addpart (3)
9 - curl_mime_data (3)
10 - curl_mime_filename (3)
11 - curl_mime_name (3)
12Protocol:
13 - HTTP
14 - IMAP
15 - SMTP
16Added-in: 7.56.0
17---
19# NAME
21curl_mime_filedata - set a mime part's body data from a file contents
23# SYNOPSIS
25~~~c
26#include <curl/curl.h>
28CURLcode curl_mime_filedata(curl_mimepart *part,
29 const char *filename);
30~~~
32# DESCRIPTION
34curl_mime_filedata(3) sets a mime part's body content from the named
35file's contents. This is an alternative to curl_mime_data(3) for setting
36data to a mime part.
38*part* is the part's to assign contents to.
40*filename* points to the null-terminated file's path name. The pointer can
41be NULL to detach the previous part contents settings. Filename storage can
42be safely be reused after this call.
44As a side effect, the part's remote filename is set to the base name of the
45given *filename* if it is a valid named file. This can be undone or
46overridden by a subsequent call to curl_mime_filename(3).
48The contents of the file is read during the file transfer in a streaming
49manner to allow huge files to get transferred without using much memory. It
50therefore requires that the file is kept intact during the entire request.
52If the file size cannot be determined before actually reading it (such as for
53a character device or named pipe), the whole mime structure containing the
54part is transferred using chunks by HTTP but is rejected by IMAP.
56Setting a part's contents multiple times is valid: only the value set by the
57last call is retained.
59# %PROTOCOLS%
61# EXAMPLE
63~~~c
64int main(void)
66 curl_mime *mime;
67 curl_mimepart *part;
69 CURL *curl = curl_easy_init();
70 if(curl) {
71 /* create a mime handle */
72 mime = curl_mime_init(curl);
74 /* add a part */
75 part = curl_mime_addpart(mime);
77 /* send data from this file */
78 curl_mime_filedata(part, "image.png");
80 /* set name */
81 curl_mime_name(part, "data");
82 }
84~~~
86# %AVAILABILITY%
88# RETURN VALUE
90This function returns a CURLcode indicating success or error.
92CURLE_OK (0) means everything was OK, non-zero means an error occurred, see
93libcurl-errors(3). If CURLOPT_ERRORBUFFER(3) was set with curl_easy_setopt(3)
94there can be an error message stored in the error buffer when non-zero is
95returned.
97CURLE_READ_ERROR is only an indication that the file is not yet readable: it
98can be safely ignored at this time, but the file must be made readable before
99the pertaining easy handle is performed.
Diagnostics4 git calls · 38 ms
CallStatusSizeTime038 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=149
git.response.cache=UPDATING
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=33
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2001.3 KiB · hit33 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1346
git.response.cache=HIT
git.response.duration_ms=33
git.fetch.wants=30f380f405405fa60a8d8973cb24a3c773afe61d
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1346
git.pkt.payload.max=1325
git.sideband.band1.bytes=1324
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e17b675d2f2a7e
Request
69f5a8a9…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format