private FileUploadResult PartialFileUpload(byte[] imageData, string extension) { const int chunkSize = 512 * 1024; // 512 KB var service = new DOMAService { Url = WebServiceUrl }; string fileName = new Random().Next(0, 100000000) + "." + extension; int position = 0; while (position < imageData.Length) { int length = Math.Min(chunkSize, imageData.Length - position); var buffer = new byte[length]; Array.Copy(imageData, position, buffer, 0, length); position += length; var uploadPartialFileRequest = new UploadPartialFileRequest { Username = Username, Password = Password, FileName = fileName, Data = buffer }; var uploadPartialFileResponse = service.UploadPartialFile(uploadPartialFileRequest); if (!uploadPartialFileResponse.Success) { return(new FileUploadResult { ErrorMessage = uploadPartialFileResponse.ErrorMessage, Success = false }); } } return(new FileUploadResult { Success = true, FileName = fileName }); }
private Task<UploadPartialFileResponse> UploadPartialFile(byte[] image, string fileExtension, DOMAServicePortType doma) { var request = new UploadPartialFileRequest { Data = image, FileName = Guid.NewGuid().ToString() + "." + fileExtension, Username = Username, Password = Password }; return Task<UploadPartialFileResponse>.Factory.FromAsync(doma.BeginUploadPartialFile, doma.EndUploadPartialFile, request, null); }