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

                return(remoteStreamInfo.RemoteStream);
            }

            return(new MemoryStream());
        }
Пример #2
0
 /// <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(Contents, FormData,
                                                                    _cancellationToken));
 }
Пример #3
0
        /// <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());
        }