名前空間: microsoft.graph
重要
Microsoft Graph の /beta
バージョンの API は変更される可能性があります。 実稼働アプリケーションでこれらの API を使用することは、サポートされていません。 v1.0 で API を使用できるかどうかを確認するには、Version セレクターを使用します。
アプリがファイルの範囲を反復的にアップロードし、ファイルを Outlook アイテムに添付できるようにするアップロード セッションを作成します。 アイテムには 、メッセージ または イベントを指定できます。
ファイル サイズが 3 MB から 150 MB の場合は、この方法を使用してファイルを添付します。 3 MB 未満のファイルを添付するには、Outlook アイテムの attachments ナビゲーション プロパティに対して操作を行いますPOST
。メッセージまたはイベントに対してこれを行う方法を参照してください。
応答の一部として、このアクションは、後続のシーケンシャル PUT
クエリで使用できるアップロード URL を返します。 各 PUT
操作の要求ヘッダーを使用すると、アップロードする正確なバイト範囲を指定できます。 これにより、アップロード中にネットワーク接続が切断された場合に備えて、転送を再開できます。
アップロード セッションを使用して Outlook アイテムにファイルを添付する手順を次に示します。
- アップロード セッションを作成します。
- そのアップロード セッション内で、ファイルのすべてのバイトがアップロードされ、ファイルが指定された項目に添付されるまで、バイト範囲 (毎回最大 4 MB) を反復的にアップロードします。
- 後でアクセスするために添付ファイルの ID を保存します。
- 省略可能: アップロード セッションを削除します。
例については、「 Outlook メッセージまたはイベントに大きなファイルを添付 する」を参照してください。
ヒント
Exchange Onlineを使用すると、管理者はメッセージの添付ファイルを含む Microsoft 365 メールボックスのメッセージ サイズ制限をカスタマイズできます。 既定では、このメッセージ サイズの制限は 35 MB です。 テナントの既定の制限を超える添付ファイルをサポートするように 最大メッセージ サイズをカスタマイズ する方法について説明します。
重要
共有メールボックスまたは委任されたメールボックス内のメッセージまたはイベントに大きなファイルを添付する場合は、 既知の問題 に注意してください。
この API は、次の国内クラウド展開で使用できます。
グローバル サービス |
米国政府機関 L4 |
米国政府機関 L5 (DOD) |
21Vianet が運営する中国 |
✅ |
❌ |
❌ |
✅ |
アクセス許可
この API の最小特権としてマークされているアクセス許可またはアクセス許可を選択します。
アプリで必要な場合にのみ、より高い特権のアクセス許可またはアクセス許可を使用します。 委任されたアクセス許可とアプリケーションのアクセス許可の詳細については、「 アクセス許可の種類」を参照してください。 これらのアクセス許可の詳細については、 アクセス許可のリファレンスを参照してください。
アクセス許可の種類 |
最小特権アクセス許可 |
特権の高いアクセス許可 |
委任 (職場または学校のアカウント) |
Calendars.ReadWrite |
Mail.ReadWrite |
委任 (個人用 Microsoft アカウント) |
Calendars.ReadWrite |
Mail.ReadWrite |
アプリケーション |
Calendars.ReadWrite |
Mail.ReadWrite |
HTTP 要求
ファイルをイベントに添付するためのアップロード セッションを作成するには:
POST /me/events/{id}/attachments/createUploadSession
ファイルをメッセージに添付するためのアップロード セッションを作成するには:
POST /me/messages/{id}/attachments/createUploadSession
名前 |
説明 |
Authorization |
ベアラー {token}。 必須です。
認証と承認の詳細については、こちらをご覧ください。 |
要求本文
要求本文で、次のパラメーターを含む JSON オブジェクトを指定します。
パラメーター |
型 |
説明 |
AttachmentItem |
attachmentItem |
アップロードおよび添付するアイテムの属性を表します。 少なくとも、添付ファイルの種類 (file )、名前、ファイルのサイズを指定します。 |
応答
成功した場合、このメソッドは 201 Created
応答コードと、応答本文に新しい uploadSession オブジェクトを返します。
注:
uploadSession 応答オブジェクトの一部として返される uploadUrl プロパティは、後続PUT
のクエリがファイルのバイト範囲をアップロードするための不透明な URL です。 これには、expirationDateTime で期限切れになる後続PUT
のクエリに適した認証トークンが含まれています。 この URL はカスタマイズしないでください。
nextExpectedRanges プロパティは、アップロード元の次のファイル バイトの場所 (例: "NextExpectedRanges":["2097152"]
) を指定します。 ファイル内のバイトを順番にアップロードする必要があります。
例
例 1: 下書きメッセージに大きな添付ファイルを追加するアップロード セッションを作成する
次の例は、指定されたメッセージへの後続のファイル アップロード操作で使用できるアップロード セッションを作成する方法を示しています。
要求
POST https://graph.microsoft.com/beta/me/messages/AAMkADI5MAAIT3drCAAA=/attachments/createUploadSession
Content-type: application/json
{
"AttachmentItem": {
"attachmentType": "file",
"name": "flower",
"size": 3483322
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Me.Messages.Item.Attachments.CreateUploadSession;
using Microsoft.Graph.Beta.Models;
var requestBody = new CreateUploadSessionPostRequestBody
{
AttachmentItem = new AttachmentItem
{
AttachmentType = AttachmentType.File,
Name = "flower",
Size = 3483322L,
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.Messages["{message-id}"].Attachments.CreateUploadSession.PostAsync(requestBody);
mgc-beta users messages attachments create-upload-session post --user-id {user-id} --message-id {message-id} --body '{\
"AttachmentItem": {\
"attachmentType": "file",\
"name": "flower",\
"size": 3483322\
}\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphusers "github.com/microsoftgraph/msgraph-beta-sdk-go/users"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphusers.NewItemCreateUploadSessionPostRequestBody()
attachmentItem := graphmodels.NewAttachmentItem()
attachmentType := graphmodels.FILE_ATTACHMENTTYPE
attachmentItem.SetAttachmentType(&attachmentType)
name := "flower"
attachmentItem.SetName(&name)
size := int64(3483322)
attachmentItem.SetSize(&size)
requestBody.SetAttachmentItem(attachmentItem)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
createUploadSession, err := graphClient.Me().Messages().ByMessageId("message-id").Attachments().CreateUploadSession().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.users.item.messages.item.attachments.createuploadsession.CreateUploadSessionPostRequestBody createUploadSessionPostRequestBody = new com.microsoft.graph.beta.users.item.messages.item.attachments.createuploadsession.CreateUploadSessionPostRequestBody();
AttachmentItem attachmentItem = new AttachmentItem();
attachmentItem.setAttachmentType(AttachmentType.File);
attachmentItem.setName("flower");
attachmentItem.setSize(3483322L);
createUploadSessionPostRequestBody.setAttachmentItem(attachmentItem);
var result = graphClient.me().messages().byMessageId("{message-id}").attachments().createUploadSession().post(createUploadSessionPostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const uploadSession = {
AttachmentItem: {
attachmentType: 'file',
name: 'flower',
size: 3483322
}
};
await client.api('/me/messages/AAMkADI5MAAIT3drCAAA=/attachments/createUploadSession')
.version('beta')
.post(uploadSession);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Users\Item\Messages\Item\Attachments\CreateUploadSession\CreateUploadSessionPostRequestBody;
use Microsoft\Graph\Beta\Generated\Models\AttachmentItem;
use Microsoft\Graph\Beta\Generated\Models\AttachmentType;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CreateUploadSessionPostRequestBody();
$attachmentItem = new AttachmentItem();
$attachmentItem->setAttachmentType(new AttachmentType('file'));
$attachmentItem->setName('flower');
$attachmentItem->setSize(3483322);
$requestBody->setAttachmentItem($attachmentItem);
$result = $graphServiceClient->me()->messages()->byMessageId('message-id')->attachments()->createUploadSession()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Mail
$params = @{
AttachmentItem = @{
attachmentType = "file"
name = "flower"
size = 3483322
}
}
# A UPN can also be used as -UserId.
New-MgBetaUserMessageAttachmentUploadSession -UserId $userId -MessageId $messageId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.users.item.messages.item.attachments.create_upload_session.create_upload_session_post_request_body import CreateUploadSessionPostRequestBody
from msgraph_beta.generated.models.attachment_item import AttachmentItem
from msgraph_beta.generated.models.attachment_type import AttachmentType
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = CreateUploadSessionPostRequestBody(
attachment_item = AttachmentItem(
attachment_type = AttachmentType.File,
name = "flower",
size = 3483322,
),
)
result = await graph_client.me.messages.by_message_id('message-id').attachments.create_upload_session.post(request_body)
応答
注: ここに示す応答オブジェクトは、読みやすさのために短縮されている場合があります。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#microsoft.graph.uploadSession",
"uploadUrl": "https://outlook.office.com/api/beta/Users('a8e8e219-4931-95c1-b73d-62626fd79c32@72aa88bf-76f0-494f-91ab-2d7cd730db47')/Messages('AAMkADI5MAAIT3drCAAA=')/AttachmentSessions('AAMkADI5MAAIT3k0uAAA=')?authtoken=eyJhbGciOiJSUzI1NiIsImtpZCI6IktmYUNIUlN6bllHMmNI",
"expirationDateTime": "2019-09-25T01:09:30.7671707Z",
"nextExpectedRanges": [
"0-"
]
}
例 2: 下書きメッセージに大きなインライン添付ファイルを追加するアップロード セッションを作成する
次の例は、下書きメッセージに大きなインライン添付ファイルを追加するために使用できるアップロード セッションを作成する方法を示しています。
インライン添付ファイルの場合は、 isInline プロパティを に true
設定し、 contentId プロパティを使用して添付ファイルの CID を次に示すように指定します。 下書きメッセージの本文で、同じ CID 値を使用して、CID HTML 参照タグを使用して添付ファイルを含める位置を示します (例: <img src="cid:my_inline_picture">
)。 ファイルが正常にアップロードされると、レンダリングされたメッセージには、指定された場所のメッセージ本文の一部として添付ファイルが含まれます。
要求
POST https://graph.microsoft.com/beta/me/messages/AAMkAGUwNjQ4ZjIxLTQ3Y2YtNDViMi1iZjc4LTMA=/attachments/createUploadSession
Content-type: application/json
{
"AttachmentItem": {
"attachmentType": "file",
"name": "scenary",
"size": 7208534,
"isInline": true,
"contentId": "my_inline_picture"
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Me.Messages.Item.Attachments.CreateUploadSession;
using Microsoft.Graph.Beta.Models;
var requestBody = new CreateUploadSessionPostRequestBody
{
AttachmentItem = new AttachmentItem
{
AttachmentType = AttachmentType.File,
Name = "scenary",
Size = 7208534L,
IsInline = true,
ContentId = "my_inline_picture",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Me.Messages["{message-id}"].Attachments.CreateUploadSession.PostAsync(requestBody);
mgc-beta users messages attachments create-upload-session post --user-id {user-id} --message-id {message-id} --body '{\
"AttachmentItem": {\
"attachmentType": "file",\
"name": "scenary",\
"size": 7208534,\
"isInline": true,\
"contentId": "my_inline_picture"\
}\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphusers "github.com/microsoftgraph/msgraph-beta-sdk-go/users"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphusers.NewItemCreateUploadSessionPostRequestBody()
attachmentItem := graphmodels.NewAttachmentItem()
attachmentType := graphmodels.FILE_ATTACHMENTTYPE
attachmentItem.SetAttachmentType(&attachmentType)
name := "scenary"
attachmentItem.SetName(&name)
size := int64(7208534)
attachmentItem.SetSize(&size)
isInline := true
attachmentItem.SetIsInline(&isInline)
contentId := "my_inline_picture"
attachmentItem.SetContentId(&contentId)
requestBody.SetAttachmentItem(attachmentItem)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
createUploadSession, err := graphClient.Me().Messages().ByMessageId("message-id").Attachments().CreateUploadSession().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.users.item.messages.item.attachments.createuploadsession.CreateUploadSessionPostRequestBody createUploadSessionPostRequestBody = new com.microsoft.graph.beta.users.item.messages.item.attachments.createuploadsession.CreateUploadSessionPostRequestBody();
AttachmentItem attachmentItem = new AttachmentItem();
attachmentItem.setAttachmentType(AttachmentType.File);
attachmentItem.setName("scenary");
attachmentItem.setSize(7208534L);
attachmentItem.setIsInline(true);
attachmentItem.setContentId("my_inline_picture");
createUploadSessionPostRequestBody.setAttachmentItem(attachmentItem);
var result = graphClient.me().messages().byMessageId("{message-id}").attachments().createUploadSession().post(createUploadSessionPostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const uploadSession = {
AttachmentItem: {
attachmentType: 'file',
name: 'scenary',
size: 7208534,
isInline: true,
contentId: 'my_inline_picture'
}
};
await client.api('/me/messages/AAMkAGUwNjQ4ZjIxLTQ3Y2YtNDViMi1iZjc4LTMA=/attachments/createUploadSession')
.version('beta')
.post(uploadSession);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Users\Item\Messages\Item\Attachments\CreateUploadSession\CreateUploadSessionPostRequestBody;
use Microsoft\Graph\Beta\Generated\Models\AttachmentItem;
use Microsoft\Graph\Beta\Generated\Models\AttachmentType;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new CreateUploadSessionPostRequestBody();
$attachmentItem = new AttachmentItem();
$attachmentItem->setAttachmentType(new AttachmentType('file'));
$attachmentItem->setName('scenary');
$attachmentItem->setSize(7208534);
$attachmentItem->setIsInline(true);
$attachmentItem->setContentId('my_inline_picture');
$requestBody->setAttachmentItem($attachmentItem);
$result = $graphServiceClient->me()->messages()->byMessageId('message-id')->attachments()->createUploadSession()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Mail
$params = @{
AttachmentItem = @{
attachmentType = "file"
name = "scenary"
size = 7208534
isInline = $true
contentId = "my_inline_picture"
}
}
# A UPN can also be used as -UserId.
New-MgBetaUserMessageAttachmentUploadSession -UserId $userId -MessageId $messageId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.users.item.messages.item.attachments.create_upload_session.create_upload_session_post_request_body import CreateUploadSessionPostRequestBody
from msgraph_beta.generated.models.attachment_item import AttachmentItem
from msgraph_beta.generated.models.attachment_type import AttachmentType
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = CreateUploadSessionPostRequestBody(
attachment_item = AttachmentItem(
attachment_type = AttachmentType.File,
name = "scenary",
size = 7208534,
is_inline = True,
content_id = "my_inline_picture",
),
)
result = await graph_client.me.messages.by_message_id('message-id').attachments.create_upload_session.post(request_body)
応答
注: ここに示す応答オブジェクトは、読みやすさのために短縮されている場合があります。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.uploadSession",
"uploadUrl": "https://outlook.office.com/api/gv1.0/users('a8e8e219-4931-95c1-b73d-62626fd79c32@72aa88bf-76f0-494f-91ab-2d7cd730db47')/messages('AAMkAGUwNjQ4ZjIxLTQ3Y2YtNDViMi1iZjc4LTMA=')/AttachmentSessions('AAMkAGUwNjQ4ZjIxLTAAA=')?authtoken=eyJhbGciOiJSUzI1NiIsImtpZCI6IjFTeXQ1bXdXYVh5UFJ",
"expirationDateTime": "2021-12-27T14:20:12.9708933Z",
"nextExpectedRanges": [
"0-"
]
}