This repository was archived by the owner on Jan 19, 2021. It is now read-only.
Add-PnPFile with -Stream #2872
Unanswered
BassemNKhalil
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm trying to build a Sync script to upload files from an external system to SPO. I'm trying to hook the response from web service that returns the document to an Add-PnPFile with Stream (to avoid saving files to local disk).
Basically if I do this, the file is uploaded to SPO but corrupted (opening PDF file shows an error and cannot be opened)
$fileStream = Invoke-RestMethod -Uri $fileUri -Credential $cred
$memoryStream = [IO.MemoryStream]::new([Text.Encoding]::UTF8.GetBytes($fileStream))
Add-PnPFile -FileName $name -Folder $DocLibraryName -Stream $memoryStream
If I do this instead (save the file to local path then read it from there) everything works fine
Invoke-RestMethod -Uri $fileUri -Credential $cred -OutFile $FilePathToSave
Add-PnPFile -Path $FilePathToSave -Folder $DocLibraryName
I'm assuming I need to use a different encoding or use a different stream other than IO.MemoryStream but I could not find any samples to suggest the right way of doing it.
Thanks,
B
Beta Was this translation helpful? Give feedback.
All reactions