/// <summary>
 /// Read the non-file contents as form data.
 /// </summary>
 /// <returns>A <see cref="Task"/> representing the post processing.</returns>
 public override Task ExecutePostProcessingAsync()
 {
     // This method predates support for cancellation, and we need to make sure it is always invoked when
     // ExecutePostProcessingAsync is called for compatability.
     return(MultipartFormDataStreamProviderHelper.ReadFormDataAsync(this.Contents, this.FormData,
                                                                    this._cancellationToken));
 }
        /// <summary>
        /// This body part stream provider examines the headers provided by the MIME multipart parser
        /// and decides whether it should return a file stream or a memory stream for the body part to be
        /// written to.
        /// </summary>
        /// <param name="parent">The parent MIME multipart HttpContent instance.</param>
        /// <param name="headers">Header fields describing the body part</param>
        /// <returns>The <see cref="Stream"/> instance where the message body part is written to.</returns>
        public override Stream GetStream(HttpContent parent, HttpContentHeaders headers)
        {
            if (MultipartFormDataStreamProviderHelper.IsFileContent(parent, headers))
            {
                return(base.GetStream(parent, headers));
            }

            return(new MemoryStream());
        }
        /// <inheritdoc />
        public override Stream GetStream(HttpContent parent, HttpContentHeaders headers)
        {
            if (MultipartFormDataStreamProviderHelper.IsFileContent(parent, headers))
            {
                RemoteStreamInfo remoteStreamInfo = this.GetRemoteStream(parent, headers);
                if (remoteStreamInfo == null)
                {
                    throw Error.InvalidOperation(Resources.RemoteStreamInfoCannotBeNull,
                                                 "GetRemoteStream", this.GetType().Name);
                }
                this.FileData.Add(new MultipartRemoteFileData(headers, remoteStreamInfo.Location, remoteStreamInfo.FileName));

                return(remoteStreamInfo.RemoteStream);
            }

            return(new MemoryStream());
        }