matlab.net.http.io.FileProvider Class
Namespace: matlab.net.http.io
Superclasses: matlab.net.http.io.ContentProvider
, matlab.mixin.Copyable
ContentProvider to send files
Description
Use a FileProvider
object as a convenient way to send one or more files to
a server.
The matlab.net.http.io.FileProvider
class is a handle
class.
Creation
Description
providers = FileProvider(
constructs
an array of files
)FileProviders
, one for each file in the
files
array. Each entry sends one file to the server.
To terminate the file transfer before reaching the end of the file, set the
FileSize
property to the number of bytes desired. To decide where
to end the transfer based on the file contents while it is being read, write a subclass
and override getData
to
examine the data being read and set the stop
return value to end the
transfer.
providers = FileProvider(
specifies options for opening the files.files
,permission
,machineformat
,encoding
)
providers = FileProvider(
constructs
fileIds
)FileProviders
specified by file identifiers. The files are read starting
at the current file position indicator to the end of the file. The file identifiers are
not closed when the transfer is complete. This method is useful if the file is already
open, or when you want to transfer just the trailing part of the file. To do this, open
the file, set the file position indicator to the start of the data in the file that you
want to transfer, and then pass that file identifier into this constructor. You can also
set FileSize
to limit the total number of bytes or write a subclass
to control when to end the transfer.
Input Arguments
files
— File names
string | string array | character vector | cell array of character vectors
One or more file names, specified as a string, string array, character vector, or
cell array of character vectors. For more information about the use of file names, see
fopen
.
Data Types: char
| string
permission
— File access type
w+
(default) | u+
| u
| T
| value allowed by fopen
function
File access type, specified as a string. If permission
is
specified, it must allow write access. The default value is 'w+'
,
which opens or creates a file for reading and writing and discards existing contents,
if any.
Data Types: char
| string
machineformat
— Order for reading or writing bytes or bits
any value allowed by fopen
Order for reading or writing bytes or bits, specified as any value allowed by the
fopen
function.
Data Types: char
| string
encoding
— Character encoding
any value allowed by fopen
Character encoding, specified as any value allowed by the
fopen
function.
Data Types: char
| string
fileIds
— File identifiers
double | array of double
One or more file identifiers, specified as a double or an array of double.
Properties
Public Properties
Filename
— Full path of file
string
Full path of the file, derived from the input argument, specified as a string.
Attributes:
GetAccess | public |
SetAccess | public |
Dependent | true |
FileSize
— Number of bytes to transmit
empty (default) | double
Number of bytes to transmit, specified as double.
Attributes:
GetAccess | public |
SetAccess | public |
Request
— Request message to send
matlab.net.http.RequestMessage
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:
GetAccess | public |
SetAccess | matlab.net.http.RequestMessage |
Header
— Header fields of message or part
matlab.net.http.HeaderField.empty
(default) | matlab.net.http.HeaderField
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 aGenericField
, then ignore the one inHeader
.If the one in
Request.Header
is not aGenericField
, then replace it with the one inHeader
.
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 |
ForceChunked
— Indicate whether to force chunked transfer coding
false
(default) | true
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 |
Protected Properties
CurrentDelegate
— ContentProvider
to which this provider is delegating
matlab.net.http.io.ContentProvider
| empty
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 |
MyDelegator
— ContentProvider
that delegated to this provider
matlab.net.http.io.ContentProvider.empty
(default) | matlab.net.http.io.ContentProvider
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
Public Methods
getData | Next buffer of data to send in HTTP request message from FileProvider |
Specialized Operators and Functions
These methods specialize standard MATLAB operators and functions and inherited methods for objects in this class.
string |
|
show | Display |
Protected Methods
complete | Complete HTTP header for ContentProvider |
preferredBufferSize | Preferred buffer size for ContentProvider |
expectedContentLength | Content length of ContentProvider |
start | Start data transfer from ContentProvider |
restartable | Indicate whether ContentProvider is restartable |
reusable | Indicate whether ContentProvider is reusable |
delegateTo | Delegate to another provider |
More About
Class Hierarchy
Version History
Introduced in R2018a
See Also
RequestMessage
| MessageBody
| MultipartProvider
| MultipartFormProvider
| FileConsumer
| fopen
| getData
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)