Method | Request URI |
---|---|
post | /API/Transfer/File/?sessionId=value |
URI Parameter | Description |
---|---|
sessionId | The current session ID. Specifying via an Authorization request header instead is recommended. |
Authorization: Bearer <Current session ID> |
Response Code | Description |
---|---|
200 | The operation completed successfully. |
400 | The request contained one or more invalid parameters. |
This example will login and upload the file 'C:\Temp\SomeExportFile.dbie' and then will import the file with it's transferFileId with the project ID 'bd767e1f-1fd2-4411-8b70-af9fdfd763e3'.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | using System.Net; using System.Net.Http; using System.Runtime.Serialization; using System.Web.Script.Serialization; ... using (HttpClient httpClient = new HttpClient()) { // Get Session Id var logonOptions = new { accountName = "admin" , password = "1234" , cultureName = string .Empty, deleteOtherSessions = true , isWindowsLogOn = false }; JavaScriptSerializer serializer = new JavaScriptSerializer(); var requestBodyAsString = serializer.Serialize(logonOptions); StringContent content = new StringContent( requestBodyAsString, Encoding.UTF8, "application/json" ); string jsonString = string .Empty; using (var response = httpClient.PostAsync(logonUri, content).Result) { Console.WriteLine( "LogOn - Success" ); jsonString = response.Content.ReadAsStringAsync().Result; } // ************************************************************************ // Upload the transfer file. // ************************************************************************ var obj = (Dictionary< string , object >)serializer.DeserializeObject(jsonString); string sessionId = obj[ "sessionId" ].ToString(); var multiPartRequestBody = new System.Net.Http.MultipartFormDataContent(); multiPartRequestBody.Headers.ContentType.MediaType = "multipart/form-data" ; string filePath = @"C:\Temp\SomeExportFile.dbie" ; string fileName = new FileInfo(filePath).Name; Guid[] transferFileIds = null ; using (Stream fileStream = System.IO.File.OpenRead(filePath)) { using (StreamContent streamContent = new StreamContent(fileStream)) { // Add an Authorization header httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( "Bearer" , sessionId); multiPartRequestBody.Add(streamContent, fileName, fileName); using (var response = httpClient.PostAsync(url, multiPartRequestBody).Result) { if (response.StatusCode == HttpStatusCode.OK) { Console.WriteLine( "Upload the transfer file - Success" ); // An array of Guids. string jsonObject = response.Content.ReadAsStringAsync().Result; transferFileIds = (Guid[])serializer.Deserialize(jsonObject, typeof (Guid[])); } } } } string transferFileId = transferFileIds.First().ToString(); // ************************************************************************ // Import the transfer // ************************************************************************ // Define the request body HttpContent requestBody = null ; requestBody = new StringContent( @" { ""importConfiguration"": { ""includeTokens"":false, ""__classType"":""dundas.transfer.ImportConfig"", ""transferFileUncPath"":"""", ""transferFileId"":""" + transferFileId + @""", ""source"":""InternalStorageId"", ""importEntityTransferVersionPolicy"":""CurrentVersionOnly"", ""groupMembershipTransferPolicy"":""DoNotImport"", ""includeUserProjects"":true, ""includeReferencedItems"":true, ""includeCustomAttributes"":false, ""accountIds"":[], ""groupIds"":[], ""tenantIds"":[], ""customAttributeIds"":[], ""fileSystemEntryIds"":[""bd767e1f-1fd2-4411-8b70-af9fdfd763e3""], ""appSettingTransferSpecs"":[], ""includeCubeData"":false, ""includeContextualData"":false, ""includeResourceData"":true, ""overwriteDataConnectorSettings"":false }, ""includeSubentriesInResultDetails"":false } }" , Encoding.UTF8, "application/json" ); using (var response = httpClient.PostAsync(url, requestBody).Result) { if (response.StatusCode == HttpStatusCode.OK) { Console.WriteLine( "Import the transfer - Success" ); //HTTP Status code as well as a <b>Dundas.BI.WebApi.Models.TransferResultData</b> //object or a error message. string jsonObject = response.Content.ReadAsStringAsync().Result; } } } |