Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Client bug]: SDK is missing option to provide $format QueryOption #1621

Closed
sopelt opened this issue Jan 18, 2023 · 11 comments · Fixed by microsoftgraph/msgraph-metadata#568 or #2332
Closed

Comments

@sopelt
Copy link

sopelt commented Jan 18, 2023

Describe the bug
The Graph API provides a way to retrieve the binary content of a sharepoint drive item while converting its type (e.g. from docx to pdf, or other options when using beta instead of 1.0) as documented here.
The current Microsoft Graph rc does not seem to provide any way of providing a format. I suspect the generated ContentRequestBuilderGetRequestConfiguration should have QueryParameters.Format to set that.

To Reproduce
await GraphServiceClient.Drives[drive.Id].Items[item.Id].Content.GetAsync()

Expected behavior
await GraphServiceClient.Drives[drive.Id].Items[item.Id].Content.GetAsync(c => c.QueryParameters.Format = "PDF")

Client version
Microsoft.Graph/5.0.0-rc.2

Desktop (please complete the following information):
Win 11

Additional context
In the 4.x SDK such parameters seem to have been available to manually add as Microsoft.Graph.QueryOption but that seems to have gone away in 5.x (core 3.x)

@Arash-Sabet
Copy link

@andrueastman Any updates on this issue? This is a roadblock for the document conversion application we have.

@Arash-Sabet
Copy link

Arash-Sabet commented Mar 10, 2023

@sopelt I tried the following approach but the converted/downloaded PDF File did not seem to have a right format (I renamed the file's extension to docx and MS Word was able to open it). Acrobat reader failed to open the file after saving the content's stream:

var requestBuilder = graphClient
   .DirectoryObjects
   .ToGetRequestInformation(config => config.QueryParameters.Filter = "format=pdf");
var pdfStream = await graphClient.Drives[drive.Id].Items[item.Id].Content.GetAsync(c => c.Options = requestBuilder.RequestOptions.ToList(), cancellationToken);

Even using the filter like config.QueryParameters.Filter ="format eq 'pdf'" or config.QueryParameters.Filter ="format eq pdf" was not conclusive. Please feel free to try to see if you can make it work and keep me posted. Thanks.

/cc @andrueastman

@andrueastman
Copy link
Member

This is a metadata issue causing the missing template.

At the moment this can be worked around as below.

var requestInformation = graphClient.Drives["driveId"].Items["fileId"].Content.ToGetRequestInformation();
requestInformation.UrlTemplate += "{?format}"; // Add the format query parameter to the template and query parameter.
requestInformation.QueryParameters.Add("format", "pdf");
var stream = await graphClient.RequestAdapter.SendPrimitiveAsync<Stream>(requestInformation);

@Arash-Sabet
Copy link

@andrueastman Thanks. Any ETA on when a permanent fix will be rolled out?

@erikmf12
Copy link

This is pretty substantial functionality to leave out of this new version. Any idea as to when this will be implemented correctly?

@erikmf12
Copy link

erikmf12 commented Aug 3, 2023

This is a metadata issue causing the missing template.

At the moment this can be worked around as below.

var requestInformation = graphClient.Drives["driveId"].Items["fileId"].Content.ToGetRequestInformation();
requestInformation.UrlTemplate += "{?format}"; // Add the format query parameter to the template and query parameter.
requestInformation.QueryParameters.Add("format", "pdf");
var stream = await graphClient.RequestAdapter.SendPrimitiveAsync<Stream>(requestInformation);

@andrueastman This workaround worked for me until I upgraded from .NET 6 to .NET 7. I'm now getting this error when trying to use this method:

EDIT: This didn't seem to be an issue with .NET 7. This seemed to be an issue with a type of .xlsx file. I'm using excel templates in D365 and one template is returning this error. I've tried recreating a different .xlsx template with bare bones features and returned the same error. Can't find any relationship between the file and the error.

The server returned an unexpected status code and no error factory is registered for this code: 406

Do you have any suggestions?

@mkoehlerstb
Copy link

Any updates on @erikmf12's last update? I am seeing the same error:

The server returned an unexpected status code and no error factory is registered for this code: 406

It seems he is using .NET 7. My code is .NET 6

I have narrowed it down to Excel files that are "large" So far I have narrowed the range to work at 6.21MB and lower and confirmed to fail at 12.89 MB or larger. Where the cutoff is between the two sizes is something we are working on.

@erikmf12
Copy link

@mkoehlerstb My issue was due to the PDF conversion is limited to 250 pages. This means that if the PDF generated is over 250 pages it returns this error. I didn't find this initially since I was working with a template and the data being provided by the template was out of my control.

@mkoehlerstb
Copy link

@erikmf12 Thank you! You probably just pulled days of work off my plate.

@nor0x
Copy link

nor0x commented Oct 22, 2023

Any updates on @erikmf12's last update? I am seeing the same error:

The server returned an unexpected status code and no error factory is registered for this code: 406

It seems he is using .NET 7. My code is .NET 6

I have narrowed it down to Excel files that are "large" So far I have narrowed the range to work at 6.21MB and lower and confirmed to fail at 12.89 MB or larger. Where the cutoff is between the two sizes is something we are working on.

Any updates on this issue?
I'm seeing the same issue with the code from @erikmf12 no exotic documents on my side here - I'm testing with a 10 page .docx and 10 page .pptx file

the following code works for me if the document is already in PDF format - so no conversion is happening.

@sopelt I tried the following approach but the converted/downloaded PDF File did not seem to have a right format (I renamed the file's extension to docx and MS Word was able to open it). Acrobat reader failed to open the file after saving the content's stream:

var requestBuilder = graphClient
   .DirectoryObjects
   .ToGetRequestInformation(config => config.QueryParameters.Filter = "format=pdf");
var pdfStream = await graphClient.Drives[drive.Id].Items[item.Id].Content.GetAsync(c => c.Options = requestBuilder.RequestOptions.ToList(), cancellationToken);

Even using the filter like config.QueryParameters.Filter ="format eq 'pdf'" or config.QueryParameters.Filter ="format eq pdf" was not conclusive. Please feel free to try to see if you can make it work and keep me posted. Thanks.

/cc @andrueastman

@andrueastman andrueastman self-assigned this Jan 31, 2024
@raeesgillani
Copy link

raeesgillani commented Feb 1, 2024

@andrueastman any updates on this since?

I am using:

RequestInformation requestInformation = client.Drives[siteDriveId].Root.ItemWithPath(filePath).Content.ToGetRequestInformation();
requestInformation.UrlTemplate += "{?format}";
requestInformation.QueryParameters.Add("format", "pdf");
Stream stream = await client.RequestAdapter.SendPrimitiveAsync<Stream>(requestInformation);

However, conversion is only working on one very small docx file (84.6KB), does not seem to work for pdf(628KB) to pdf, nor xlsx(438KB) to pdf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment