添加附件Add attachment

命名空间:microsoft.graphNamespace: microsoft.graph

使用此 API 可将 附件 添加到现有 事件中。Use this API to add an attachment to an existing event. 此操作将限制可添加到 3 MB 以下的附件的大小。This operation limits the size of the attachment you can add to under 3 MB.

如果组织者将附件添加到会议事件中,则组织者随后可以 更新 事件以发送附件并为每个与会者同时更新事件。If an organizer adds an attachment to a meeting event, the organizer can subsequently update the event to send the attachment and update the event for each attendee as well.

权限Permissions

要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions.

权限类型Permission type 权限(从最低特权到最高特权)Permissions (from least to most privileged)
委派(工作或学校帐户)Delegated (work or school account) Calendars.ReadWriteCalendars.ReadWrite
委派(个人 Microsoft 帐户)Delegated (personal Microsoft account) Calendars.ReadWriteCalendars.ReadWrite
应用程序Application Calendars.ReadWriteCalendars.ReadWrite

HTTP 请求HTTP request

用户的默认日历中的事件附件。Attachments for an event in the user's default calendar.

POST /me/events/{id}/attachments
POST /users/{id | userPrincipalName}/events/{id}/attachments

POST /me/calendar/events/{id}/attachments
POST /users/{id | userPrincipalName}/calendar/events/{id}/attachments

属于用户的默认 calendarGroup日历 中的 事件 附件。Attachments for an event in a calendar belonging to the user's default calendarGroup.

POST /me/calendars/{id}/events/{id}/attachments
POST /users/{id | userPrincipalName}/calendars/{id}/events/{id}/attachments

POST /me/calendargroup/calendars/{id}/events/{id}/attachments
POST /users/{id | userPrincipalName}/calendargroup/calendars/{id}/events/{id}/attachments

属于用户的 calendarGroup日历 中的 事件 附件。Attachments for an event in a calendar belonging to a user's calendarGroup.

POST /me/calendargroups/{id}/calendars/{id}/events/{id}/attachments
POST /users/{id | userPrincipalName}/calendargroups/{id}/calendars/{id}/events/{id}/attachments

请求标头Request headers

名称Name 类型Type 说明Description
AuthorizationAuthorization stringstring Bearer {token}。必需。Bearer {token}. Required.
Content-TypeContent-Type stringstring 实体正文中的数据性质。必需。Nature of the data in the body of an entity. Required.

请求正文Request body

在请求正文中,提供 attachment 对象的 JSON 表示形式。In the request body, supply a JSON representation of attachment object.

响应Response

如果成功,此方法在响应正文中返回 201 Created 响应代码和 attachment 对象。If successful, this method returns 201 Created response code and attachment object in the response body.

示例(文件附件)Example (file attachment)

请求Request

下面是一个请求示例。Here is an example of the request.

POST https://graph.microsoft.com/v1.0/me/events/AAMkAGI1AAAt9AHjAAA=/attachments
Content-type: application/json
Content-length: 151

{
    "@odata.type": "#microsoft.graph.fileAttachment",
    "name": "menu.txt",
    "contentBytes": "base64bWFjIGFuZCBjaGVlc2UgdG9kYXk="   
}

在请求正文中,提供 attachment 对象的 JSON 表示形式。In the request body, supply a JSON representation of attachment object.

响应Response

下面是一个响应示例。Here is an example of the response.

HTTP 201 Created
Content-type: application/json

{
    "@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('cd209b0b-3f83-4c35-82d2-d88a61820480')/events('AAMkAGI1AAAt9AHjAAA%3D')/attachments/$entity",
    "@odata.type":"#microsoft.graph.fileAttachment",
    "id":"AAMkAGI1AAAt9AHjAAABEgAQAEdBogju-MJEu6Ngg-1_W0g=",
    "lastModifiedDateTime":"2017-04-15T03:21:49Z",
    "name":"menu.txt",
    "contentType":"text/plain",
    "size":178,
    "isInline":false,
    "contentId":null,
    "contentLocation":null,
    "contentBytes":"bWFjIGFuZCBjaGVlc2UgdG9kYXk="
}

示例(项目附件)Example (item attachment)

请求Request

下面将一个事件附加到另一个事件作为项目附件的示例。Here is an example which attaches an event with another event as an item attachment.

POST https://graph.microsoft.com/v1.0/me/events/AAMkAGI1AAAt9AHjAAA=/attachments
Content-type: application/json
Content-length: 600

{
  "@odata.type": "#microsoft.graph.itemAttachment",
  "name": "Holiday event", 
  "item": {
        "@odata.type": "microsoft.graph.event",
        "subject": "Discuss gifts for children",
        "body": {
            "contentType": "HTML",
            "content": "Let's look for funding!"
         },
         "start": {
             "dateTime": "2016-12-02T18:00:00",
             "timeZone": "Pacific Standard Time"
          },
          "end": {
             "dateTime": "2016-12-02T19:00:00",
             "timeZone": "Pacific Standard Time"
          }
    }
}
响应Response

下面是一个响应示例。Here is an example of the response.

HTTP 201 Created
Content-type: application/json
Content-length: 162

{
    "@odata.context":"https://graph.microsoft.com/v1.0/$metadata#me/events('AAMkAGI1AAAt9AHjAAA=')/attachments/$entity",
    "@odata.type":"#microsoft.graph.itemAttachment",
    "@odata.id":"https://graph.microsoft.com/v1.0/users('fdcbcf34-2505-4d07-be5b-0a55b699d157@41a5b830-45ac-4f1b-9bfc-baafa3b7db2e')/events('AAMkAGI1AAAt9AHjAAA=')/attachments('AAMkADNkN2Jp5JVnQIe9r0=')",
    "id":"AAMkADNkNJp5JVnQIe9r0=",
    "lastModifiedDateTime":"2016-12-01T22:27:13Z",
    "name":"Holiday event",
    "contentType":null,
    "size":2473,
    "isInline":false
}