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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Post Import In Group API ERROR InvalidFileSizeError

While Using Post Import In Group API, encounter the following error:

400 Bad Request from POST https://api.powerbi.com/v1.0/myorg/groups/{group_id}/imports?datasetDisplayName={datasetDisplayName}...

Spoiler
Error Response: {"error":{"code":"InvalidFileSizeError","pbi.error":{"code":"InvalidFileSizeError","parameters":{"FileSize":"9223372036854775807"},"details":[],"exceptionCulprit":1}}}

The pbix file size in question is approximately 2MB.

NOTE: Same API works fine when publishing a 2MB Excel file.

Please find the below code in Java using reactive Web Client

public Mono<String> publishPowerBIReport(String fileName, FilePart fileP) throws Exception {
String filename = fileP.filename();
Path tempFilePath = Paths.get(System.getProperty("java.io.tmpdir"), filename);
File file = tempFilePath.toFile();
FileSystemResource fileSystemResource = new FileSystemResource(file);
String boundary = "---------------------------" + Long.toHexString(System.currentTimeMillis());
MultipartBodyBuilder builder = new MultipartBodyBuilder();
builder.part("file", fileSystemResource)
.header(HttpHeaders.CONTENT_DISPOSITION, "form-data; name=\"file\"; filename=\""+filename+"\";")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);
MultiValueMap<String, HttpEntity<?>> multipartData = builder.build();
webClientBuild();
String token = getAccessToken();
return webClient.post().uri(uriBuilder -> uriBuilder
.path(RELATIVE_URL)
.queryParam("datasetDisplayName", fileName)
.queryParam("subfolderId", SUB_FOLDER_ID)
.queryParam("nameConflict", "Overwrite")
.build())
.body(BodyInserters.fromMultipartData(multipartData))
.header(HttpHeaders.AUTHORIZATION, "Bearer " + token)
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE+"; boundary=" + boundary)
.retrieve()
.bodyToMono(String.class)
.doOnSuccess(
response -> System.out.println("File uploaded successfully: " + response + "***END****")
)
.doOnError(WebClientResponseException.class, error ->
System.err.println("Error uploading file: --->" + "Error Message :: " + error.getMessage() + " Error Response :: " + error.getResponseBodyAsString() + "***END****")
);

}
4 REPLIES 4
ancm
New Member

We face the same problem. Did you manage to solve this ?

Anonymous
Not applicable

Hi @Anonymous , Thank you for your response.
I had tested same file using Postman and powershell, it is working fine. So looks like it's not the case of file corruption.
Also same upload code is working fine if I upload an Excel file instead of power bi with same size. As mention in PowerBi documentation that 

Supported content:

  • Power BI .pbix files
  • JSON files (.json)
  • Excel files (.xlsx)
  • SQL Server Report Definition Language files (.rdl)

 Imports - Post Import In Group - REST API (Power BI Power BI REST APIs) | Microsoft Learn

I found one difference while testing with Postman is that, postman header contain Content-Length: parameter and its calculate length at run time. In postman console I can see the calculated size of Content-Length, But when I tried to pass the same content-length using my code, its throws a different exception mention below

{
"code": "InputStreamIncorrectLengthException",
"message": "The length of the file input stream does not match the provided length. Expected: '1177397', Actual (approximate): '1177398.'"
}


I am not sure at this moment, that  Web Client in java calculate Content-Length internaly or not but looks like PowerBI Post import in gropu API required content-length too in header. Not sure how to resolve this issue.
I went through similier kind of issue discussion in below Post
https://community.fabric.microsoft.com/t5/Developer/quot-InvalidFileSizeError-quot-when-upload-for-temporary-storage/m-p/3231632#M42636

 

Anonymous
Not applicable

Hi @Anonymous ,

 

Based on the error message, ‘FileSize is recognized as 9223372036854775807’. This indicates that the Power BI API encountered an issue when parsing the file size. It could be related to the method of file upload, or it may be caused by file corruption.

 

I suggest that you consider using Postman or PowerShell to try uploading your PBIX file to rule out any issues related to the file itself. If the file uploads successfully, it is likely that the problem lies within the Java code. 

 

Here’s the PowerShell script for uploading a PBIX file to a Power BI workspace:

 

# Install required module (if not already installed)

Install-Module -Name MicrosoftPowerBIMgmt

# Sign in to Power BI (this will open a login window)

Connect-PowerBIServiceAccount

#Import

New-PowerBIReport -Path "C:\XX\XXX\XX\XXX.pbix" -Name "0902" -WorkspaceId "8xxxxx5cd9-8643-4664-a87c-7b6097xxxxxx"

 

 

Best Regards,

Bof

I think for rdl files this approach it doesn't work and I really don't understand why!!!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.