MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / UploadFile

Method UploadFile

dotnet/src/webdriver/WebElement.cs:718–744  ·  view source on GitHub ↗
(string localFile)

Source from the content-addressed store, hash-verified

716 }
717
718 private string UploadFile(string localFile)
719 {
720 string base64zip;
721 try
722 {
723 using (MemoryStream fileUploadMemoryStream = new MemoryStream())
724 {
725 using (ZipArchive zipArchive = new ZipArchive(fileUploadMemoryStream, ZipArchiveMode.Create))
726 {
727 string fileName = Path.GetFileName(localFile);
728 zipArchive.CreateEntryFromFile(localFile, fileName);
729 }
730 base64zip = Convert.ToBase64String(fileUploadMemoryStream.ToArray());
731 }
732
733 Dictionary<string, object> parameters = new Dictionary<string, object>();
734 parameters.Add("file", base64zip);
735 Response response = this.Execute(DriverCommand.UploadFile, parameters);
736
737 response.EnsureValueIsNotNull();
738 return response.Value.ToString()!;
739 }
740 catch (IOException e)
741 {
742 throw new WebDriverException("Cannot upload " + localFile, e);
743 }
744 }
745}

Callers 1

SendKeysMethod · 0.95

Calls 5

ExecuteMethod · 0.95
ToBase64StringMethod · 0.80
EnsureValueIsNotNullMethod · 0.80
AddMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected