MCPcopy Create free account
hub / github.com/SpartanJ/eepp / buildFilePart

Method buildFilePart

src/eepp/network/http.cpp:1750–1783  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1748}
1749
1750void Http::MultipartEntitiesBuilder::buildFilePart( std::ostream& ostream, IOStream* stream,
1751 const std::string& fieldName,
1752 const std::string& fileName,
1753 const std::string& contentType ) {
1754 size_t initialPos = stream->tell();
1755 stream->seek( 0 );
1756 int bytesAvailable = stream->getSize();
1757 int maxBufferSize = 1024 * 1024;
1758 int bufferSize = eemin( bytesAvailable, maxBufferSize );
1759 TScopedBuffer<char> buffer( bufferSize );
1760
1761 ostream << TWO_HYPHENS << getBoundary() << LINE_END;
1762 ostream << "Content-Disposition: form-data; name=\"" << fieldName << "\"; filename=\""
1763 << fileName << "\"" << LINE_END;
1764 ostream << "Content-Transfer-Encoding: binary" << LINE_END;
1765 ostream << "Content-Length: " << bytesAvailable << LINE_END;
1766 if ( !contentType.empty() ) {
1767 ostream << "Content-Type: " << contentType << LINE_END;
1768 }
1769 ostream << LINE_END;
1770
1771 // read file and write it into form...
1772 int bytesRead = stream->read( buffer.get(), bufferSize );
1773
1774 while ( bytesRead > 0 ) {
1775 ostream.write( buffer.get(), bufferSize );
1776 bytesAvailable -= bytesRead;
1777 bufferSize = eemin( bytesAvailable, maxBufferSize );
1778 bytesRead = stream->read( buffer.get(), bufferSize );
1779 }
1780
1781 ostream << LINE_END;
1782 stream->seek( initialPos );
1783}
1784
1785void Http::MultipartEntitiesBuilder::buildTextPart( std::ostream& ostream,
1786 const std::string& parameterName,

Callers

nothing calls this directly

Calls 8

eeminFunction · 0.85
tellMethod · 0.45
seekMethod · 0.45
getSizeMethod · 0.45
emptyMethod · 0.45
readMethod · 0.45
getMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected