Skip to content

Conversation

peombwa
Copy link
Member

@peombwa peombwa commented Oct 16, 2020

This PR proposes the following changes to properly handle file upload and download with the generated commands.

  1. Adds FileUploadCmdlet class. This will be the base class for all cmdlets that upload files i.e. -BodyParameter is of type Stream and name starts with Set-*. FileUploadCmdlet class performs the following :

    • Adds a mandatory -InFile parameter to all cmdlets that derive from FileUploadCmdlet.
    • GetFileAsStream handles getting a resolved path to the file and returns a thread safe stream.
  2. Adds PSCmdletExtensions class. This class provides helper methods that handle retrieval of valid paths and writing of streams to a file on disk.

  3. Adds directives to replace broken file upload and download logic in generated cmdlets.
    For file download, the directive:

    • Add logic that handles writing of response streams by calling WriteToFile in PSCmdletExtensions.

    For file upload, the directive:

    • Replaces generated base class with FileUploadCmdlet.
    • Makes bodyParameter optional since FileUploadCmdlet adds a mandatory -InFile parameter.
    • Adds logic handles creation of thread safe file upload stream by calling GetFileAsStream in `FileUploadCmdlet.
  4. Updates modules mapping tags and onpremisespublishingprofile directives.

Proposed Usage

# Download user profile photo.
Get-MgUserPhotoContent -UserId $userId -OutFile "c:\tmp\profile.png"

# Upload user profile photo.
Set-MgUserPhotoContent -UserId $userId -InFile "c:\tmp\newProfile.png"

# Download drive item content.
Get-MgDriveItemContent -DriveId $driveId -DriveItemId $itemId -OutFile "c:\tmp\doc.docx"

# Upload drive item content.
Set-MgDriveItemContent -DriveId $driveId -DriveItemId $itemId -InFile "c:\tmp\updatedDoc.docx"

These changes we tested against the OpenAPI docs in staging. Thanks @irvinesunday!

Closes #54 and #182

@peombwa peombwa self-assigned this Oct 16, 2020
@ddyett
Copy link
Contributor

ddyett commented Oct 22, 2020

is this correct? shouldn't it be infile?

Upload drive item content.

Set-MgDriveItemContent -DriveId $driveId -DriveItemId $itemId -OutFile "c:\tmp\updatedDoc.docx"

@ddyett
Copy link
Contributor

ddyett commented Oct 22, 2020

do we need this support for Invoke-GraphRequest too?

@georgend
Copy link
Contributor

do we need this support for Invoke-GraphRequest too?

IGR had it baked in, however, I can run the tests @peombwa has run and confirm all is well.

@peombwa
Copy link
Member Author

peombwa commented Oct 22, 2020

is this correct? shouldn't it be infile?

Upload drive item content.

Set-MgDriveItemContent -DriveId $driveId -DriveItemId $itemId -OutFile "c:\tmp\updatedDoc.docx"

This should be InFile.

@peombwa peombwa merged commit 45db45a into dev Oct 22, 2020
@peombwa peombwa deleted the po/StreamSupport branch October 22, 2020 15:30
@peombwa peombwa mentioned this pull request Oct 26, 2020
@robinmalik
Copy link

@peombwa What is $itemid in the above examples?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uploading user photo

4 participants