public async Task <DocumentForCreationResponse> AddImage(DocumentForCreationResponse documentForCreationResponse, int id) { var file = documentForCreationResponse.File; var uploadResult = new ImageUploadResult(); if (file.Length > 0) { using (var stream = file.OpenReadStream()) { var uploadParams = new ImageUploadParams() { File = new FileDescription(file.Name, stream) }; uploadResult = _cloudinary.Upload(uploadParams); } } documentForCreationResponse.Url = uploadResult.Uri.ToString(); documentForCreationResponse.PublicId = uploadResult.PublicId; documentForCreationResponse.Name = documentForCreationResponse.File.FileName; documentForCreationResponse.Type = documentForCreationResponse.File.ContentType; documentForCreationResponse.UserId = id; var assetForReturn = documentForCreationResponse; Asset asset = new Asset() { Name = documentForCreationResponse.Name, Type = documentForCreationResponse.Type, Url = documentForCreationResponse.Url, PublicId = documentForCreationResponse.PublicId, UserId = documentForCreationResponse.UserId }; await _repository.AddImage(asset); return(assetForReturn); }