2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FNetHttpHttpMultipartEntity.h
20 * @brief This is the header file for the %HttpMultipartEntity class.
22 * This header file contains the declarations of the %HttpMultipartEntity class.
25 #ifndef _FNET_HTTP_HTTP_MULTIPART_ENTITY_H_
26 #define _FNET_HTTP_HTTP_MULTIPART_ENTITY_H_
30 #include <FNetHttpHttpTypes.h>
31 #include <FNetHttpIHttpEntity.h>
33 namespace Tizen { namespace Net { namespace Http
35 class _HttpMultipartEntityImpl;
39 * The constant for the default MIME type of the string part.
41 * @brief <i> [Deprecated] </i>
42 * @deprecated This object is provided only for backward compatibility and will be deleted in the near future.
43 * Use HTTP_STRING_PART_DEFAULT_MIME_TYPE instead of this object.
47 _OSP_EXPORT_ extern const Tizen::Base::String STRING_PART_DEFAULT_MIME_TYPE;
51 * The constant for the default MIME type of the file part.
53 * @brief <i> [Deprecated] </i>
54 * @deprecated This object is provided only for backward compatibility and will be deleted in the near future.
55 * Use HTTP_FILE_PART_DEFAULT_MIME_TYPE instead of this object.
59 _OSP_EXPORT_ extern const Tizen::Base::String FILE_PART_DEFAULT_MIME_TYPE;
62 * The constant for the default MIME type of the string part ("text/plain").
66 _OSP_EXPORT_ extern const wchar_t HTTP_STRING_PART_DEFAULT_MIME_TYPE[];
69 * The constant for the default MIME type of the file part ("application/octet-stream").
73 _OSP_EXPORT_ extern const wchar_t HTTP_FILE_PART_DEFAULT_MIME_TYPE[];
76 * @class HttpMultipartEntity
77 * @brief This class represents a multipart/form-data entity as defined in RFC 2388.
81 * The %HttpMultipartEntity class represents a multipart/form-data entity as defined in RFC 2388.
82 * The multipart/form-data entity contains a series of parts.
84 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/net/http_connectivity.htm">HTTP Guide</a>.
86 * The following example demonstrates how to use the %HttpMultipartEntity class to upload the content to the server.
93 using namespace Tizen::Base;
94 using namespace Tizen::Net::Http;
97 TestHttpMultipartEntity(void)
100 HttpSession* pSession = null;
101 HttpTransaction* pTransaction = null;
102 HttpRequest* pRequest = null;
103 HttpMultipartEntity* pMultipartEntity = null;
104 String hostAddr(L"http://www.tizen.org");
106 // Creates an HTTP session.
107 pSession = new HttpSession();
108 r = pSession->Construct(NET_HTTP_SESSION_MODE_NORMAL, null, hostAddr, null);
110 pTransaction = pSession->OpenTransactionN();
111 r = pTransaction->AddHttpTransactionListener(*this);
112 r = pTransaction->SetHttpProgressListener(*this);
114 pRequest = pTransaction->GetRequest();
115 pRequest->SetMethod(NET_HTTP_METHOD_POST);
116 r = pRequest->SetUri(L"http://www.tizen.org/test");
118 pMultipartEntity = new HttpMultipartEntity();
119 r = pMultipartEntity->Construct();
121 r = pMultipartEntity->AddStringPart(L"title", L"Tizen logo");
122 r = pMultipartEntity->AddStringPart(L"date", L"2010-12-25");
123 r = pMultipartEntity->AddFilePart(L"upload", L"/Home/Tizen.jpg", L"Tizen.jpg", L"image/jpeg", L"ISO-8859-1");
125 r = pRequest->SetEntity(*pMultipartEntity);
126 r = pTransaction->Submit();
132 class _OSP_EXPORT_ HttpMultipartEntity
133 : public Tizen::Base::Object
139 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after calling this constructor.
143 * @remarks After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
145 HttpMultipartEntity(void);
148 * This destructor overrides Tizen::Base::Object::~Object().
152 virtual ~HttpMultipartEntity(void);
155 * Initializes this instance of %HttpMultipartEntity.
159 * @return An error code
160 * @exception E_SUCCESS The method is successful.
161 * @exception E_OUT_OF_MEMORY The memory is insufficient.
162 * @exception E_SYSTEM A system error has occurred.
164 result Construct(void);
167 * Initializes this instance of %HttpMultipartEntity with the specified parameters.
171 * @return An error code
172 * @param[in] boundary The boundary of multipart/form-data
173 * @exception E_SUCCESS The method is successful.
174 * @exception E_INVALID_ARG The specified input parameter is invalid.
175 * @exception E_OUT_OF_MEMORY The memory is insufficient.
176 * @exception E_SYSTEM A system error has occurred.
178 result Construct(const Tizen::Base::String& boundary);
182 * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
184 * @param[in] rhs An instance of %HttpMultipartEntity
186 HttpMultipartEntity(const HttpMultipartEntity& rhs);
189 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
191 * @param[in] rhs An instance of %HttpMultipartEntity
193 HttpMultipartEntity& operator =(const HttpMultipartEntity& rhs);
197 * Gets the length of the request content.
201 * @return The length of the content, @n
202 * else @c -1 if the content length is unknown
204 virtual long long GetContentLength(void) const;
207 * Gets the type of the request content.
211 * @return The type of the content
213 virtual Tizen::Base::String GetContentType(void) const;
216 * Adds the string part to %HttpMultipartEntity with the default MIME type and character set.
220 * @return An error code
221 * @param[in] name The name of the part
222 * @param[in] text The text of the part @n
223 * The value of @c text is encoded using the default character encoding standard ("ISO-8859-1").
224 * @exception E_SUCCESS The method is successful.
225 * @exception E_INVALID_ARG A specified input parameter is invalid.
226 * @exception E_OUT_OF_MEMORY The memory is insufficient.
227 * @exception E_INVALID_ENCODING_RANGE The @c text contains code points that are outside the bounds specified by @c encoding.
228 * @exception E_SYSTEM A system error has occurred.
229 * @remarks The default MIME type is "text/plain".
231 result AddStringPart(const Tizen::Base::String& name, const Tizen::Base::String& text);
234 * Adds the string part to %HttpMultipartEntity.
238 * @return An error code
239 * @param[in] name The name of the part
240 * @param[in] text The text of the part
241 * @param[in] mimeType The MIME type of @c text
242 * @param[in] charset The character set of @c text
243 * @param[in] encoding An encoding scheme for the specified @c text
244 * @exception E_SUCCESS The method is successful.
245 * @exception E_INVALID_ARG A specified input parameter is invalid.
246 * @exception E_OUT_OF_MEMORY The memory is insufficient.
247 * @exception E_INVALID_ENCODING_RANGE The @c text contains code points that are outside the bounds specified by @c encoding.
248 * @exception E_SYSTEM A system error has occurred.
250 result AddStringPart(const Tizen::Base::String& name, const Tizen::Base::String& text, const Tizen::Base::String& mimeType, const Tizen::Base::String& charset, const Tizen::Text::Encoding& encoding);
253 * Adds the file part to %HttpMultipartEntity with the default MIME type.
256 * @brief <i> [Compatibility] </i>
260 * @compatibility This method has compatibility issues with OSP compatible applications. @n
261 * For more information, see @ref CompIoPathPage "here".
264 * @return An error code
265 * @param[in] name The name of the part
266 * @param[in] filePath The path of the file to upload
267 * @exception E_SUCCESS The method is successful.
268 * @exception E_INVALID_ARG A specified input parameter is invalid.
269 * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed.
270 * @exception E_OUT_OF_MEMORY The memory is insufficient.
271 * @exception E_SYSTEM A system error has occurred.
272 * @remarks The default MIME type is "application/octet-stream".
274 result AddFilePart(const Tizen::Base::String& name, const Tizen::Base::String& filePath);
277 * Adds the file part to %HttpMultipartEntity.
280 * @brief <i> [Compatibility] </i>
284 * @compatibility This method has compatibility issues with OSP compatible applications. @n
285 * For more information, see @ref CompIoPathPage "here".
288 * @return An error code
289 * @param[in] name The name of the part
290 * @param[in] filePath The path of the file to upload
291 * @param[in] fileName The file name of the part
292 * @param[in] mimeType The MIME type of the content
293 * @param[in] charset The character set of the content
294 * @exception E_SUCCESS The method is successful.
295 * @exception E_INVALID_ARG A specified input parameter is invalid.
296 * @exception E_FILE_NOT_FOUND The specified file cannot be found or accessed.
297 * @exception E_OUT_OF_MEMORY The memory is insufficient.
298 * @exception E_SYSTEM A system error has occurred.
300 result AddFilePart(const Tizen::Base::String& name, const Tizen::Base::String& filePath, const Tizen::Base::String& fileName, const Tizen::Base::String& mimeType, const Tizen::Base::String& charset);
303 * Adds the binary part to %HttpMultipartEntity with the default MIME type.
307 * @return An error code
308 * @param[in] name The name of the part
309 * @param[in] fileName The file name of the part
310 * @param[in] buffer The buffer of file to upload
311 * @exception E_SUCCESS The method is successful.
312 * @exception E_INVALID_ARG A specified input parameter is invalid.
313 * @exception E_OUT_OF_MEMORY The memory is insufficient.
314 * @exception E_SYSTEM A system error has occurred.
315 * @remarks The default MIME-type is "application/octet-stream".
317 result AddFilePartByBuffer(const Tizen::Base::String& name, const Tizen::Base::String& fileName, const Tizen::Base::ByteBuffer& buffer);
320 * Adds the binary part to %HttpMultipartEntity.
324 * @return An error code
325 * @param[in] name The name of the part
326 * @param[in] fileName The file name of the part
327 * @param[in] buffer The buffer of the file to upload
328 * @param[in] mimeType The MIME type of the content
329 * @param[in] charset The character set of the content
330 * @exception E_SUCCESS The method is successful.
331 * @exception E_INVALID_ARG A specified input parameter is invalid.
332 * @exception E_OUT_OF_MEMORY The memory is insufficient.
333 * @exception E_SYSTEM A system error has occurred.
335 result AddFilePartByBuffer(const Tizen::Base::String& name, const Tizen::Base::String& fileName, const Tizen::Base::ByteBuffer& buffer, const Tizen::Base::String& mimeType, const Tizen::Base::String& charset);
339 * Checks whether the next data exists.
343 * @return @c true if the next data exists, @n
345 * @exception E_SUCCESS The method is successful.
346 * @exception E_OUT_OF_MEMORY The memory is insufficient.
347 * @exception E_INVALID_STATE The method invoked is invalid.
348 * @exception E_SYSTEM A system error has occurred.
349 * @remarks The specific error code can be accessed using the GetLastResult() method.
351 virtual bool HasNextData(void);
354 * Gets the next data.
358 * @return The buffer to be read
359 * @param[in] recommendedSize The recommended size of the data to send
360 * @exception E_SUCCESS The method is successful.
361 * @exception E_OUT_OF_MEMORY The memory is insufficient.
362 * @exception E_INVALID_STATE The method invoked is invalid.
363 * @exception E_SYSTEM A system error has occurred.
364 * @remarks The specific error code can be accessed using the GetLastResult() method.
366 virtual Tizen::Base::ByteBuffer* GetNextDataN(int recommendedSize);
369 friend class _HttpMultipartEntityImpl;
370 _HttpMultipartEntityImpl* __pHttpMultipartEntityImpl;
372 }; // HttpMultipartEntity
374 } } } // Tizen::Net::Http
375 #endif // _FNET_HTTP_HTTP_MULTIPART_ENTITY_H_