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 Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,644 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,674 questions
0 comments No comments
{count} votes

Accepted answer
  1. MichaelHan-MSFT 18,016 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