PySide6.QtNetwork.QHttpMultiPart¶
- class QHttpMultiPart¶
- The - QHttpMultiPartclass resembles a MIME multipart message to be sent over HTTP.- Details- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - The - QHttpMultiPartresembles a MIME multipart message, as described in RFC 2046, which is to be sent over HTTP. A multipart message consists of an arbitrary number of body parts (see- QHttpPart), which are separated by a unique boundary. The boundary of the- QHttpMultiPartis constructed with the string “boundary_.oOo._” followed by random characters, and provides enough uniqueness to make sure it does not occur inside the parts itself. If desired, the boundary can still be set via- setBoundary().- As an example, consider the following code snippet, which constructs a multipart message containing a text part followed by an image part: - multiPart = QHttpMultiPart(QHttpMultiPart.FormDataType) textPart = QHttpPart() textPart.setHeader(QNetworkRequest.ContentDispositionHeader, QVariant("form-data; name=\"text\"")) textPart.setBody("my text") imagePart = QHttpPart() imagePart.setHeader(QNetworkRequest.ContentTypeHeader, QVariant("image/jpeg")) imagePart.setHeader(QNetworkRequest.ContentDispositionHeader, QVariant("form-data; name=\"image\"")) file = QFile("image.jpg") file.open(QIODevice.OpenModeFlag.ReadOnly) imagePart.setBodyDevice(file) file.setParent(multiPart) # we cannot delete the file now, so delete it with the multiPart multiPart.append(textPart) multiPart.append(imagePart) url = QUrl("http://my.server.tld") request = QNetworkRequest(url) manager = QNetworkAccessManager() reply = manager.post(request, multiPart) multiPart.setParent(reply) # delete the multiPart with the reply # here connect signals etc. - Synopsis¶- Methods¶- def - __init__()
- def - append()
- def - boundary()
- def - setBoundary()
- def - setContentType()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - class ContentType¶
- List of known content types for a multipart subtype as described in RFC 2046 and others. - Constant - Description - QHttpMultiPart.ContentType.MixedType - corresponds to the “multipart/mixed” subtype, meaning the body parts are independent of each other, as described in RFC 2046. - QHttpMultiPart.ContentType.RelatedType - corresponds to the “multipart/related” subtype, meaning the body parts are related to each other, as described in RFC 2387. - QHttpMultiPart.ContentType.FormDataType - corresponds to the “multipart/form-data” subtype, meaning the body parts contain form elements, as described in RFC 2388. - QHttpMultiPart.ContentType.AlternativeType - corresponds to the “multipart/alternative” subtype, meaning the body parts are alternative representations of the same information, as described in RFC 2046. - See also 
 - Constructs a - QHttpMultiPartwith content type- MixedTypeand sets- parentas the parent object.- See also - __init__(contentType[, parent=None])
- Parameters:
- contentType – - ContentType
- parent – - QObject
 
 
 - Constructs a - QHttpMultiPartwith content type- contentTypeand sets parent as the parent object.- See also - Appends - httpPartto this multipart.- boundary()¶
- Return type:
 
 - returns the boundary. - See also - setBoundary(boundary)¶
- Parameters:
- boundary – - QByteArray
 
 - Sets the boundary to - boundary.- Usually, you do not need to generate a boundary yourself; upon construction the boundary is initiated with the string “boundary_.oOo._” followed by random characters, and provides enough uniqueness to make sure it does not occur inside the parts itself. - See also - setContentType(contentType)¶
- Parameters:
- contentType – - ContentType
 
 - Sets the content type to - contentType. The content type will be used in the HTTP header section when sending the multipart message via- post(). In case you want to use a multipart subtype not contained in- ContentType, you can add the “Content-Type” header field to the- QNetworkRequestby hand, and then use this request together with the multipart message for posting.- See also