var resultOut = new List<ImageUploadResult>(); var streamProvider = new MultipartMemoryStreamProvider(); streamProvider = await Request.Content.ReadAsMultipartAsync(streamProvider); foreach ( var item in streamProvider.Contents.Where(c => !string.IsNullOrEmpty(c.Headers.ContentDisposition.FileName)) ) { using (Stream stFileSource = new MemoryStream(await item.ReadAsByteArrayAsync())) { byte[] fileBytes; fileBytes = new Byte[stFileSource.Length]; stFileSource.Read(fileBytes, 0, Convert.ToInt32(stFileSource.Length)); resultOut.Add(new ImageUploadResult() { FileName = item.Headers.ContentDisposition.FileName, DataObject = fileBytes, Key = "" // Guid.NewGuid().ToString() }); } } return Request.CreateResponse(HttpStatusCode.OK, resultOut.ToArray());and this is the code which is saving that info after it was send back again:
StringBuilder sb = new StringBuilder(); foreach (ImageUploadResult attachment in messageViewModel.Attachments) { byte[] fileArray = Encoding.UTF8.GetBytes(attachment.DataObject.ToString()); // attachment.FileName already has double quotes, for some reason sb.Append("<attachment filename=" + attachment.FileName + "><data format=\"hex\">" + fileArray.ToHexString() + "</data></attachment>"); }So, my concern here about getting that byte array for the file correctly.