示例#1
0
        public static async Task <IImageFile> CreateImageFromRequest(string container, string fileName, HttpRequestMessage request)
        {
            var provider = new MultipartMemoryStreamProvider();
            await request.Content.ReadAsMultipartAsync(provider);

            IImageFile imageFile = CreateImageModel(container);

            foreach (var item in provider.Contents)
            {
                switch (item.Headers.ContentDisposition.Name.Replace("\"", ""))
                {
                case "AvatarFile":
                    var fileData = await item.ReadAsByteArrayAsync();

                    var contentType = item.Headers.ContentType.ToString();
                    var fileSize    = fileData.Length;
                    imageFile.SetMetadata(container, fileName, contentType, fileData);
                    break;
                }
            }

            return(imageFile);
        }