Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
SandMonster
Frequent Visitor

Help importing a pbix file to my workspace using powershell

Hi all, I am currently working with powershell, trying to create a routine to get a pbix file from our azure git repo, and I have been able to get the file without problems, the thing is... I am having problems trying to import the file to my workspace using powershell, the reason is, when I get access to my file the response returns a string which is, I assume, the decoded version of the file, so, when I try to encode it back and send it to my workspace I get an error "Bad request" and that's it, does anyone have a clue on how to correctly encode the file and import it?? 

 

Note: When I do it locally, getting a file from a local path, I don't have problems importing files/adding multipartformdatacontent. 

 

Thanks in advance and here's a sample of my code.

 

 $blob =  [string]::Format("https://dev.azure.com/MYCOMPANY/{0}/_apis/git/repositories/{1}/blobs/{fileId}?api-version=5.0", {projectName}, {repositoryID})

 $file = Invoke-RestMethod -Uri $blob -Method Get -Headers $header -ContentType "application/octet-stream" 

                $enc = [system.Text.Encoding]::UTF8.GetBytes($file)
                $stream =  New-Object System.IO.MemoryStream (,$enc)
                $bytecontent = New-Object System.Net.Http.Headers.ContentDispositionHeaderValue "form-data"
                $bytecontent.Name = "uploadFile";
                $bytecontent.FileName = "uploadFile.pbix";
                $streamContent = New-Object System.Net.Http.StreamContent $stream
                $streamContent.Headers.ContentDisposition = $bytecontent
                $content = New-Object System.Net.Http.MultipartFormDataContent
                $content.Add($streamContent)  

$Importresponse = $httpClient.PostAsync($uriImport, $content).Result        
        $stream.Dispose()
        $stream.Close()
        $content.Dispose()        

 

this what the initial response looks like, when I get the file from our azure repothis what the initial response looks like, when I get the file from our azure repo

0 REPLIES 0

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.