Skip to content

Stream Support Improvements - #433

Merged
Peter Ombwa (peombwa) merged 9 commits into
devfrom
po/StreamSupport
Oct 22, 2020
Merged

Peter Ombwa (peombwa) merged 9 commits into
devfrom
po/StreamSupport

Conversation

@peombwa

@peombwa Peter Ombwa (peombwa) commented Oct 16, 2020 •

Copy link
Copy Markdown
Member

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 Irvine Sunday (@irvinesunday)!

Closes #54 and #182

@ddyett

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

do we need this support for Invoke-GraphRequest too?

@georgend

Copy link
Copy Markdown
Contributor

do we need this support for Invoke-GraphRequest too?

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

@peombwa

Copy link
Copy Markdown
Member Author

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.

@robinmalik

Copy link
Copy Markdown

Peter Ombwa (@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