Microsoft Graph - OneDrive API - 下载前转换为 jpg
Microsoft Graph - OneDrive API - Convert to jpg before download
我正在尝试访问两个 OneDrive 项目。第一个是 .docx
,第二个是 .tif
。我想在下载它们之前将它们转换为 .jpg
。
当我运行请求内容时...
// gets access to the service
GraphServiceClient graphServiceClient = await GetGraphServiceClient();
// get the item
DriveItem item = await graphServiceClient
.Drive
.Root
.ItemWithPath("xxx")
.Request()
.GetAsync();
// set up query params
List<Option> options = new List<Option>();
options.Add(new QueryOption("format", "jpg"));
// get content stream for item, converted to .jpg format
item.Content = await graphServiceClient
.Drive
.Root
.ItemWithPath("xxx")
.Content.Request(options)
.GetAsync();
这会引发 Unknown Error
服务异常。
我认为这可能是一个格式不正确的请求,但我可以将该 QueryOption 格式更改为 pdf
并且如您所料 returns。
有谁知道这里可能出了什么问题,为什么我不能检索 jpg 但可以检索 pdf?
Microsoft Graph v1.0 仅支持 converting to pdf
. The ability to convert to other formats is only supported by the Beta endpoint。
/v1.0
支持:
format=pdf
/beta
支持:
format=pdf
format=html
format=glb
format=jpg
遗憾的是,OneDrive documentation 没有区分 production 和 beta 功能。因此,我不建议将其作为主要来源。就这样很容易被绊倒。
为了转换为 jpg
,您需要使用 Beta 端点,但将 BaseUrl
属性 设置为 "https://graph.microsoft.com/beta"
。请务必针对这种情况 仅 执行此操作,而不是全局执行。 Beta 端点对于生产来说不够稳定,因此它应该只用于 dev/test 和 "there is no other way" 场景。
我正在尝试访问两个 OneDrive 项目。第一个是 .docx
,第二个是 .tif
。我想在下载它们之前将它们转换为 .jpg
。
当我运行请求内容时...
// gets access to the service
GraphServiceClient graphServiceClient = await GetGraphServiceClient();
// get the item
DriveItem item = await graphServiceClient
.Drive
.Root
.ItemWithPath("xxx")
.Request()
.GetAsync();
// set up query params
List<Option> options = new List<Option>();
options.Add(new QueryOption("format", "jpg"));
// get content stream for item, converted to .jpg format
item.Content = await graphServiceClient
.Drive
.Root
.ItemWithPath("xxx")
.Content.Request(options)
.GetAsync();
这会引发 Unknown Error
服务异常。
我认为这可能是一个格式不正确的请求,但我可以将该 QueryOption 格式更改为 pdf
并且如您所料 returns。
有谁知道这里可能出了什么问题,为什么我不能检索 jpg 但可以检索 pdf?
Microsoft Graph v1.0 仅支持 converting to pdf
. The ability to convert to other formats is only supported by the Beta endpoint。
/v1.0
支持:
format=pdf
/beta
支持:
format=pdf
format=html
format=glb
format=jpg
遗憾的是,OneDrive documentation 没有区分 production 和 beta 功能。因此,我不建议将其作为主要来源。就这样很容易被绊倒。
为了转换为 jpg
,您需要使用 Beta 端点,但将 BaseUrl
属性 设置为 "https://graph.microsoft.com/beta"
。请务必针对这种情况 仅 执行此操作,而不是全局执行。 Beta 端点对于生产来说不够稳定,因此它应该只用于 dev/test 和 "there is no other way" 场景。