/// <summary> /// Creates a new instance of the <see cref="FileMultipartSection"/> class /// </summary> /// <param name="section">The section from which to create the <see cref="FileMultipartSection"/></param> /// <param name="header">An already parsed content disposition header</param> public FileMultipartSection(MultipartSection section, ContentDispositionHeaderValue header) { if (!header.IsFileDisposition()) { throw new ArgumentException($"Argument must be a file section", nameof(section)); } Section = section; _contentDispositionHeader = header; Name = HeaderUtilities.RemoveQuotes(_contentDispositionHeader.Name).ToString(); FileName = HeaderUtilities.RemoveQuotes( _contentDispositionHeader.FileNameStar.HasValue ? _contentDispositionHeader.FileNameStar : _contentDispositionHeader.FileName).ToString(); }
/// <summary> /// Converts the section to a form section /// </summary> /// <param name="section">The section to convert</param> /// <returns>A form section</returns> public static FormMultipartSection AsFormDataSection(this MultipartSection section) { if (section == null) { throw new ArgumentNullException(nameof(section)); } try { return(new FormMultipartSection(section)); } catch { return(null); } }
public static MultipartSection EnableRewind(this MultipartSection section, Action <IDisposable> registerForDispose, int bufferThreshold = DefaultBufferThreshold, long?bufferLimit = null) { if (section == null) { throw new ArgumentNullException(nameof(section)); } if (registerForDispose == null) { throw new ArgumentNullException(nameof(registerForDispose)); } var body = section.Body; if (!body.CanSeek) { var fileStream = new FileBufferingReadStream(body, bufferThreshold, bufferLimit, _getTempDirectory); section.Body = fileStream; registerForDispose(fileStream); } return(section); }
/// <summary> /// Creates a new instance of the <see cref="FileMultipartSection"/> class /// </summary> /// <param name="section">The section from which to create the <see cref="FileMultipartSection"/></param> /// <remarks>Reparses the content disposition header</remarks> public FileMultipartSection(MultipartSection section) : this(section, section.GetContentDispositionHeader()) { }