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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

multipartmimestreamformatexception error when importing pbix files using rest api

hi,

 

So I'm using powershell to automate my power BI reports into my workspace through imports API.

here's the code which I'm using :

    $PBIXuri="my azure blob storage url",
    $Workspaceurl="https://api.powerbi.com/v1.0/myorg/groups/mygroups/imports?datasetDisplayName=myreportname",
    $AccessToken="my oauth token"

    #download my pbix file from azure blob storage
    $cli = New-Object System.Net.WebClient
    $exportpbix = $cli.DownloadData($PBIXuri)

    $powerBiBody = @'
    --exptest
    Content-Disposition: form-data; name="file";
    Content-Type: application/x-zip-compressed

    {0}
    --exptest--

    '@

    #set my pbix file into request body
    $encoding = [System.Text.Encoding]::GetEncoding('iso-8859-1')
    $body = $powerBiBody -f $encoding.GetString($exportpbix)

    $headers = @{
    "Authorization" = "Bearer " + $AccessToken}

    Invoke-RestMethod -Uri $Workspaceurl -Method Post -Headers $headers -Body $body -ContentType "multipart/form-data; boundary=--exptest"

 

but it always return an error like :

 

Invoke-RestMethod :     {"error":
     {"code":"MultiPartMimeStreamFormatException","pbi.error": 
       {"code":"MultiPartMimeStreamFormatException",
        "parameters":{},
        "details":[],
        "exceptionCulprit":1
        }
      }
    }

 

where do I went wrong on my code?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

finally found the problem.

the code itself has no problem, the problem is on the ps1 file itself. 

I don't know why but the ps1 file on my local is being recognized as a UNIX based files. because my OS is windows I just changed it into win based files again and it works just fine.

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

Anonymous
Not applicable

Hi @lbendlin 

 

yes, I've tried my code in the sandbox and it works just fine.

this code is for my web app where it will call my PowerShell to import a PBI file from Azure Storage.

the strange thing about this [MultiPartMimeStreamFormatException] error is, it's only occurred when I try to run the code from my local environment. while if I released it to my app container on top of Azure it worked just fine.

 

Anonymous
Not applicable

finally found the problem.

the code itself has no problem, the problem is on the ps1 file itself. 

I don't know why but the ps1 file on my local is being recognized as a UNIX based files. because my OS is windows I just changed it into win based files again and it works just fine.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors