| 1748 | } |
| 1749 | |
| 1750 | void 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 | |
| 1785 | void Http::MultipartEntitiesBuilder::buildTextPart( std::ostream& ostream, |
| 1786 | const std::string& parameterName, |