in src/Microsoft.Health.Dicom.Api/Web/AspNetCoreMultipartReader.cs [37:90]
internal AspNetCoreMultipartReader(
string contentType,
Stream body,
ISeekableStreamConverter seekableStreamConverter,
IOptions<StoreConfiguration> storeConfiguration)
{
EnsureArg.IsNotNull(contentType, nameof(contentType));
EnsureArg.IsNotNull(body, nameof(body));
EnsureArg.IsNotNull(seekableStreamConverter, nameof(seekableStreamConverter));
EnsureArg.IsNotNull(storeConfiguration?.Value, nameof(storeConfiguration));
_seekableStreamConverter = seekableStreamConverter;
_storeConfiguration = storeConfiguration;
if (!MediaTypeHeaderValue.TryParse(contentType, out MediaTypeHeaderValue media) ||
!media.MediaType.Equals(KnownContentTypes.MultipartRelated, StringComparison.InvariantCultureIgnoreCase))
{
throw new UnsupportedMediaTypeException(
string.Format(CultureInfo.InvariantCulture, DicomApiResource.UnsupportedContentType, contentType));
}
string boundary = HeaderUtilities.RemoveQuotes(media.Boundary).ToString();
if (string.IsNullOrWhiteSpace(boundary))
{
throw new UnsupportedMediaTypeException(
string.Format(CultureInfo.InvariantCulture, DicomApiResource.InvalidMultipartContentType, contentType));
}
// Check to see if the root content type was specified or not.
if (media.Parameters != null)
{
foreach (NameValueHeaderValue parameter in media.Parameters)
{
if (TypeParameterName.Equals(parameter.Name.ToString(), StringComparison.OrdinalIgnoreCase))
{
_rootContentType = HeaderUtilities.RemoveQuotes(parameter.Value).ToString();
}
else if (StartParameterName.Equals(parameter.Name.ToString(), StringComparison.OrdinalIgnoreCase))
{
// TODO: According to RFC2387 3.2, the root section can be specified by using the
// start parameter. For now, we will assume that the first section is the "root" section
// and will add support later. Throw exception in case start is specified.
throw new NotSupportedException(DicomApiResource.StartParameterIsNotSupported);
}
}
}
_multipartReader = new MultipartReader(boundary, body)
{
// set the max length of each section in bytes
BodyLengthLimit = _storeConfiguration.Value.MaxAllowedDicomFileSize,
};
}