Upload a File to SPO Doc Library in Web API Using an All In Memory Approach? #1393
-
Situational Background I work at a company that has a farm server side process that uploads files daily to a SharePoint 2013 document library. The on-prem site has been migrated to SPO & due to firewall restrictions, the process will NOT be able to directly upload files to a SPO document library. We have an internal to external gateway API that the process can utilize in order access an Azure Web API which is where I am able to make the upload file call utilizing PnP.Core in C#. I have a controller action that reads the file from the request body & successfully uploads the file to the library, but I'm questioning if my approach could be improved? In a nutshell, the request body is read into a MemoryStream then converted to a byte array which gets written to a file. Next the file is read into a FileStream which PnP.Core uses as an arg in order to upload the file to the library. The big question for this approach is: Can I avoid writing & reading the file in the Web API before uploading & do it all in memory utilizing some sort of Stream object approach? Here's my code snippets `var boundary = HeaderUtilities.RemoveQuotes( var reader = new MultipartReader(boundary, Request.Body); var section = await reader.ReadNextSectionAsync(); // Use the PnP Context factory to get a PnPContext for the given configuration
}` Parse file from body & write it `private async Task CreateFile(MultipartReader reader, MultipartSection? section, string filePath)
}` Any advice would be appeciated!!! Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@RobertWoehr : the AddAsync method on the |
Beta Was this translation helpful? Give feedback.
@jansenbe Wow! You're my Hero!!! And such a simple answer! I tested your suggestion out on .xlsx, .docx, & .pdf and it seems to be working as expected! Thank you for such a fantastic & timely response!