Upload file using upload component with MsGraph

Having difficulty uploading a file using MsGraph. I had gone through all of MsGraph method with their documentation. I was able to upload files using Postman such as PUT https://graph.microsoft.com/v1.0/me/drive/items/{parent-id}:/{filename}:/content or PUT https://graph.microsoft.com/v1.0/drives/{driveId}/items/{parent-id}:/{filename}:/content, but whenever I use the same method from Radzen with parameters filled out, it will not work.

It seems Radzen does not generate the right methods at the moment. Here is how to upload a file until we add support for that.

  1. Add a custom method to the Angular component. Open the xxx.component.ts file that Radzen has generated for your xxx page.
  2. Add the following code in it
    uploadFile(driveId: string, folderId: string, file: any) {
    return this.httpClient
      .put(
        `https://graph.microsoft.com/v1.0/drives('${driveId}')/items/${folderId}:/${file.name}:/content`,
        file
      )
      .subscribe(result => result);
    }
    
  3. Invoke the custom method via Execute code action and pass the driveId, folderId and file parameters. If you are using the Upload component use ${event.files[0]}

1 Like