How to download a file attachment with golang sdk

Arnaud Lemaignen 20 Reputation points
2023-03-17T16:50:32.5166667+00:00

Hi
I dont find anywhere examples on how downloading a mail attachment using msgraph-sdk-go v0.56.0

I have access to the attachment as followed
attachment,err := client.UsersById(emailUser).MessagesById(msgId).AttachmentsById(attId).Get(context.Background(), nil)

but then I dont see any methods to extract the content of the attachment.

how can this be achieved?
many thanks in advance

Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Shivam Dhiman 6,081 Reputation points
    2023-03-20T07:09:00.21+00:00

    Hi @Arnaud Lemaignen

    Seems like you have posted same on GitHub. How to download a file attachment with golang sdk
    Currently, as a workaround yes you can use below code and use another request builder that performs a similar function to download a file attachment with Golang:

    rawUrl := "https://graph.microsoft.com/v1.0/users/{user-id}/messages/{message-id}/attachments/{attachment-id}/$value"
    builder := users.NewItemPhotoValueContentRequestBuilder(rawUrl, requestAdapter)
    attachmentValue, err := builder.Get(context.Background(), nil)
    

    Hope this helps.
    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.