You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
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.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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