WsContents
Overview
The WsContents
class represents the contents or parts of an HTTP request. It provides functionality to access metadata and content details of uploaded files or form data in a request. The contents include attributes such as the content name, field name, content type, size, and raw byte data. Additionally, it allows retrieval of the content as a string with a specified encoding.
Key methods include getName()
to get the content name, getFieldName()
to retrieve the field name, getContentType()
to access the MIME type, and getSize()
to get the content size in bytes. The class also provides methods like getBytes()
to obtain raw byte data and getString(encoding)
to convert the content into a string using a specified encoding.
Properties Summarized
Properties Detailed
bytes
Get contents bytes.
Type Array
Sample
var request = plugins.rest_ws.getRequest();
var contents = request.getContents();
if (contents.length > 0) {
var bytes = contents[0].getBytes();
}
contentType
Get contents content type.
Type String
Sample
var request = plugins.rest_ws.getRequest();
var contents = request.getContents();
if (contents.length > 0) {
var contentType = contents[0].getContentType();
}
fieldName
Get contents field name.
Type String
Sample
var request = plugins.rest_ws.getRequest();
var contents = request.getContents();
if (contents.length > 0) {
var fieldName = contents[0].getFieldName();
}
name
Get contents name.
Type String
Sample
var request = plugins.rest_ws.getRequest();
var contents = request.getContents();
if (contents.length > 0) {
var name = contents[0].getName();
}
size
Get contents size.
Type Number
Sample
var request = plugins.rest_ws.getRequest();
var contents = request.getContents();
if (contents.length > 0) {
var size = contents[0].getSize();
}
string
Get contents as string.
Type String
Sample
var request = plugins.rest_ws.getRequest();
var contents = request.getContents();
if (contents.length > 0) {
var string = contents[0].getString('UTF-8');
}
Last updated
Was this helpful?