This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

matlab.net.http.io.ImageProvider class

Package: matlab.net.http.io
Superclasses: matlab.net.http.io.ContentProvider

ContentProvider to send MATLAB image data

Description

Use an ImageProvider object to convert and send MATLAB® image data in an HTTP RequestMessage. This provider converts the data to one of the standard types, as specified by the Content-Type of the request or properties in this object. This provider also converts an image file to a different format.

By default, if you specify an image Content-Type in the RequestMessage, for example "image/jpeg" and RequestMessage.Body is a MessageBody containing your image data, then MATLAB assumes that MessageBody.Data is image data and tries to convert it appropriately. To control how your data is converted, use an ImageProvider in RequestMessage.Body.

If the RequestMessage does not contain a Content-Type header field, then this provider adds the appropriate image Content-Type to the header. Otherwise, the header field is not modified and conversion is done as specified in the properties of this object, even if its value is inconsistent with the Content-Type field.

The matlab.net.http.io.ImageProvider class is a handle class.

Creation

Description

provider = ImageProvider(data,arg1,...,argN) creates a provider that converts MATLAB image data to the format specified by arg1,...,argN, setting the Data property to data and the Arguments property to arg1,...,argN.

provider = ImageProvider(filename,arg1,...,argN) obtains the image data from the file filename and sends it in the format specified in arg1,...,argN or the Content-Type field, setting the Filename property to filename.

While this provider can convert a file in one format to data in another format, it is not designed to send an image file as is. To send a file without changing its type, use a FileProvider.

Properties

expand all

Public Properties

This is the value specified as the Data argument to the constructor, if any, or the data converted from the filename argument. Set this value to a string scalar or character vector before sending the message containing this provider.

If a subclass author wants to set this property before MATLAB calls the start method, then set the value in the complete method. If you change this property, then the change takes effect with the next call to start.

Attributes:

GetAccess

public

SetAccess

public

Arguments to the imwrite function, specified as a cell array. This is the value specified to the constructor containing a list of arguments as documented for imwrite, but omitting the image data and file name arguments.

Subclass authors can set this property before MATLAB calls start, for example, in complete. If you change these values, then the changes do not take effect until the next call to start.

Attributes:

GetAccess

public

SetAccess

public

Dependent

true

Name of the file containing the image data, specified as a string. This is the value specified as the filename argument to the constructor, if any. It is read-only.

The format of filename is derived from the file name extension, which might be different from the fmt argument in arg1,...,argN or the Content-Type in the message. This constructor syntax allows you to send an image file in one format to a server that expects it in a different format. However, some conversions are incompatible. For example, you cannot convert an RGB file like JPEG to a GIF format.

Attributes:

GetAccess

public

SetAccess

private

Header fields of the message or part, specified as a vector of one or more matlab.net.http.HeaderField objects.

This property is only used by subclass authors. MATLAB sets this property before calling the provider's complete method. For non-multipart messages, MATLAB initializes this property to the contents of Request.Header, minus any matlab.net.http.field.GenericFields or empty-valued fields. The ContentProvider uses this property to add header fields that describe the data to be sent, or to add parameters to header fields already in the message. In a delegate for a MultipartProvider, MATLAB initializes this property to header fields that the delegating provider intends to insert for the part. Delegates can modify or change these fields.

Upon return from the provider's complete method, if this not a multipart message, then MATLAB reads this property and merges its contents into the header of Request. Fields in this Header with Names that do not already appear in Request.Header are added to the end of Request.Header. If a field in this Header has a Name that is the same as one in Request.Header, and both have nonempty Values, then:

  • If the one in Request.Header is a GenericField, then ignore the one in Header.

  • If the one in Request.Header is not a GenericField, then replace it with the one in Header.

If one or both of these has an empty Value, then the field is removed from Request.Header and it is not added as part of normal message completion.

If this is a delegate of a MultipartProvider, then the entire contents of this Header is used as the header of the part. Multipart delegates must not assume that Request.Header contains any fields pertaining to their own Header. A provider can determine whether it is a multipart delegate by checking whether MyDelegator is a MultipartProvider, though this test is unlikely to be needed.

MATLAB reads this property only on return from calling the provider's complete method. Changes to this array are ignored once MATLAB calls start.

Class authors should be aware that their subclasses might have added fields to this Header (in their complete method) before calling complete in their superclass. It is best to preserve such fields and not to add fields with the same names. However, adding a parameter to a field is permissible. For example, a superclass can add a charset parameter to an existing Content-Type field that does not already have one.

Attributes:

GetAccess

public

SetAccess

public

Indicate whether to force chunked transfer coding, specified as boolean. This property is of interest only to subclass authors, and is applicable only to providers that are not multipart delegates. Subclasses set ForceChunked to control whether contents should be sent using chunked transfer coding. If false (default), MATLAB decides whether to send the contents chunked, based on whether it knows the content length at the time the message is ready to be sent:

  • If MATLAB knows the content length (which is the case if the message contains a Content-Length field, or if this provider's expectedContentLength method returned a number), then MATLAB decides whether to send it chunked or not.

  • If MATLAB does not know the content length (no Content-Length field in the header and expectedContentLength returned empty), then MATLAB always sends the message chunked.

If ForceChunked is true, then MATLAB sends the message chunked regardless of whether it knows the content length, unless the known length is smaller than the chunk size. If this property is true, then the message must not contain a Content-Length field, because HTTP does not allow a chunked message to have a Content-Length field. However, you can still return a nonzero value in the expectedContentLength method if you want MATLAB to verify that you are returning the expected length of data.

When MATLAB chooses to send the message chunked, the size of each chunk is equal to the length of data returned by getData.

MATLAB reads this value after calling the complete method, before calling start. It does not set this field.

Attributes:

GetAccess

public

SetAccess

public

Request message to send, specified as a matlab.net.http.RequestMessage object.

This property is used only by subclass authors. The RequestMessage.send and RequestMessage.complete methods set this property to the RequestMessage in whose Body this provider has been placed, before calling any other methods in this provider, and before adding any additional header fields or validating the message. The provider can examine this message to see what was contained in the original request.

Delegates see the same value for this property as the delegator. ContentProviders should be aware that, if they are delegates, they are not necessarily providing the entire body of the request message, so they should not assume that header fields in this Request are pertinent to the data they are providing. Usually, delegates should ignore header fields in this request relevant to the data, such as Content-Type.

If the provider wishes to add any header fields to this message, or to modify existing ones, it should do so in its complete method by adding those fields to the Header property. The caller of complete (RequestMessage or a delegating provider) determines what to do with those fields. RequestMessage.send and RequestMessage.complete always copy these fields to the Header of the RequestMessage. A delegating provider can copy the fields to its own Header property or insert them into the message (as in the case of MultipartProvider). For more information, see the Header property.

This property is read-only.

Attributes:

GetAccesspublic
SetAccessmatlab.net.http.RequestMessage

Protected Properties

ContentProvider to which this provider is delegating, specified as a matlab.net.http.io.ContentProvider object. This property is set in the calling provider (the delegator) by the delegateTo method to indicate the current delegated provider. If there is no current delegation, then the value is empty.

The complete methods set this property to empty.

Attributes:

GetAccess

protected

SetAccess

protected

ContentProvider that delegated to this provider, specified as a matlab.net.http.io.ContentProvider object.

If a ContentProvider delegates responsibility for sending all or a portion of the message data to another provider, then this property identifies the delegating provider to the delegate. For example, a MultipartProvider delegates parts of the message to other providers, so it inserts a handle to itself in each delegate. Otherwise, MyDelegator is empty. The delegateTo method sets this property in the delegate.

Attributes:

GetAccess

protected

SetAccess

protected

Methods

expand all

More About

expand all

Introduced in R2018a