Forum Discussion

Access_Jim's avatar
Access_Jim
Copper Contributor
Jul 28, 2024

Graph API with Large Attachment Problem

I am attempting to send an EMail via the O365 Graph API with a large attachment.   I am doing this from Access VBA.   I have created an upload session and am attempting to upload the attachment in chunks with successive PUTs, but I get an error message.    I am sending this command:

 

PUT  httpx://graph.microsoft.com/v1.0/me/messages/AAMkADli...(shortened for posting)/attachments/Onboarding_Guide_v12.pdf/createUploadSession

 

And I receive this error response:

{"error":{"code":"BadRequest","message":"Resource not found for the segment 'createUploadSession'.",...

 

Any idea what is wrong with my PUT statement?

 

Jim

 

 

    • Access_Jim's avatar
      Access_Jim
      Copper Contributor
      Using the link you provided, it states: "As part of the response, this action returns an upload URL that you can use in subsequent sequential PUT queries." This is the part where I am having the problem. I have no problem creating the session. I am using https in my code.
      • Gerrit_Viehmann's avatar
        Gerrit_Viehmann
        Brass Contributor

        Access_Jim When you get a resonse similar to this:

        {
            "@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": "2024-07-30T14:20:12.9708933Z",
            "nextExpectedRanges": [
                "0-"
            ]
        }

         You store the value of uploadUrl for later use in PUTs and continue with 2 MiB chunks of the file as an answer similar to this:

        PUT https://outlook.office.com/api/gv1.0/users('a8e8e219-4931-95c1-b73d-62626fd79c32@72aa88bf-76f0-494f-91ab-2d7cd730db47')/messages('AAMkAGUwNjQ4ZjIxLTQ3Y2YtNDViMi1iZjc4LTMA=')/AttachmentSessions('AAMkAGUwNjQ4ZjIxLTAAA=')?authtoken=eyJhbGciOiJSUzI1NiIsImtpZCI6IjFTeXQ1bXdXYVh5UFJ
        Content-Type: application/octet-stream
        Content-Length: 2097152
        Content-Range: bytes 0-2097151/9483322
        {
          <bytes 0-2097151 of the file to be attached, in binary format>
        }

         and so on...

Resources