You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Power Automate HTTP请求设置SharePoint图片列并解决报错?

解决Power Automate更新SharePoint现代图片列问题

问题1:从Power Automate填充SharePoint图片列的正确方法

现代SharePoint图片列(通过“添加列>图片”创建)内部存储的是JSON格式的字符串,而非结构化对象。正确操作步骤如下:

  1. 配置HTTP请求:
    • 请求方法:PATCH(或用POST并在请求头添加X-HTTP-Method: MERGE)
    • 请求头:
      • Content-Type: application/json;odata=verbose
      • IF-MATCH: *(允许覆盖任何版本,也可使用列表项ETag实现乐观并发)
      • Accept: application/json;odata=verbose
    • 请求地址:/_api/web/lists/getbytitle('MyCustomList')/items({ListItemID})
  2. 构造正确的请求体(将图片信息序列化为转义后的JSON字符串):
    {
      "__metadata": {
        "type": "SP.Data.MyCustomListListItem"
      },
      "ImagePreviewThumbnail": "{\"type\":\"thumbnail\",\"fileName\":\"image.jpg\",\"serverUrl\":\"https://[tenant].sharepoint.com\",\"serverRelativeUrl\":\"/sites/[site-name]/Shared Documents/folder/image.jpg\"}"
    }
    

问题2:当前发送的对象格式是否正确?

不正确。你传入的是嵌套JSON对象,但现代图片列期望接收转义后的JSON字符串,直接传对象会触发Unexpected node 'StartObject'错误,因为系统需要原始字符串值而非结构化对象。

问题3:是否需要uniqueId,若需要如何可靠获取?

不需要强制使用uniqueId,仅用serverUrl、serverRelativeUrl和fileName组成的JSON字符串即可正常关联图片。如果确实需要获取文件UniqueId,可添加一个“Send an HTTP request to SharePoint”操作:

  • 请求方法:GET
  • 请求地址:/_api/web/getfilebyserverrelativeurl('{文件的ServerRelativeUrl}')?$select=UniqueId
    从返回结果中即可提取UniqueId值。

问题4:有哪些替代方案可解决该问题?

  • 方案1:使用Power Automate“Update item”操作
    部分环境中该操作已支持直接填写图片列,只需传入图片的服务器相对路径(如/sites/[site-name]/Shared Documents/folder/image.jpg),系统会自动处理格式转换。
  • 方案2:Power Apps Patch函数更新
    在Power Apps中直接调用函数:
    Patch(MyCustomList, 
          LookUp(MyCustomList, ID = ListItemID),
          {
            ImagePreviewThumbnail: {
              '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
              type: "thumbnail",
              fileName: "image.jpg",
              serverUrl: "https://[tenant].sharepoint.com",
              serverRelativeUrl: "/sites/[site-name]/Shared Documents/folder/image.jpg"
            }
          }
    )
    
  • 方案3:Microsoft Graph API更新
    调用Graph接口:
    PATCH https://graph.microsoft.com/v1.0/sites/[site-id]/lists/[list-id]/items/[item-id]/fields
    Content-Type: application/json
    
    {
      "ImagePreviewThumbnail": "{\"type\":\"thumbnail\",\"fileName\":\"image.jpg\",\"serverUrl\":\"https://[tenant].sharepoint.com\",\"serverRelativeUrl\":\"/sites/[site-name]/Shared Documents/folder/image.jpg\"}"
    }
    

问题5:如何避免仅更新图片列时,Title、Description等其他字段被清空?

  • 使用MERGE或PATCH请求(不要用PUT),这类请求仅更新请求体中指定的字段,不会覆盖未提及的字段。
  • 请求体只保留__metadata(若用odata verbose格式)和需要更新的ImagePreviewThumbnail字段,不要包含Title、Description等其他字段。
  • 若使用IF-MATCH头,设置为*或列表项当前的ETag,避免并发更新冲突。

内容的提问来源于stack exchange,提问作者Roman Dulak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 01:27:23