23 protected function build(array $data)
27 foreach ($data as $k => $v)
31 if ((is_resource($v) && get_resource_type($v) ===
'stream') || is_array($v))
33 $filename = $v[
'filename'] ?? $k;
34 $contentType = $v[
'contentType'] ??
'application/octet-stream';
36 $this->
write(
'Content-Disposition: form-data; name="' . $k .
'"; filename="' . $filename .
'"' .
"\r\n");
37 $this->
write(
'Content-Type: ' . $contentType .
"\r\n\r\n");
41 if (isset($v[
'resource']) && is_resource($v[
'resource']) && get_resource_type($v[
'resource']) ===
'stream')
43 fseek($v[
'resource'], 0);
44 while (!feof($v[
'resource']))
46 $this->
write(stream_get_contents($v[
'resource'], static::BUF_LEN));
51 if (isset($v[
'content']))
53 $this->
write($v[
'content']);
57 throw new ArgumentException(
"File `{$k}` not found for multipart upload.",
'data');
67 $this->
write(stream_get_contents($v, static::BUF_LEN));
73 $this->
write(
'Content-Disposition: form-data; name="' . $k .
'"' .
"\r\n\r\n");