How to upload file with metadata to SharePoint Online using Graph API

Kelly 81 Reputation points
2021-11-21T15:06:53.587+00:00

I am able to upload files to sharepoint online using this way: https://learn.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http.

However, in the documentation it does not mention that how to upload files with metadata (some fields are required in my library). Is there an easy way to do this?
Any help would be appreciated!
Kelly

Microsoft 365 and Office | SharePoint | Development
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. MichaelHan-MSFT 18,126 Reputation points
    2021-11-22T02:12:42.727+00:00

    Hi @Kelly ,

    As a workaround, you could use Update listItem method to set the field value after uploading the file. Below is my demo for you:

    var fieldValueSet = new FieldValueSet  
    {  
        AdditionalData = new Dictionary<string, object>()  
        {  
            {"Title", "test"},  
            {"column1", "value"}  
        }  
    };  
    await graphClient.Drives["{drive-id}"].Items["{driveitem-id}"].ListItem.Fields  
        .Request()  
        .UpdateAsync(fieldValueSet);  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    3 people found this answer helpful.

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.