Search code examples
c#.net-coreautodesk-forgeautodeskautodesk-bim360

How to read the content of a BIM 360 file as a filestream and writes it to another stream


I was looking into this document AutoDesk I am able to get Files/Folders structure and content from BIM 360 but is there a way I can read the content of a file as file stream to write it in different file(I don't want to download the file locally) in .Net core without using rest end point.


Solution

  • The getObject method (from the official Forge SDK) that is typically used to access OSS data (which BIM 360 Docs uses under the hood as well) does return System.IO.Stream already. So you should be able to stream the incoming data anywhere you need. For example, you can redirect the stream to another POST request as explained in this tutorial:

        var request = new HttpRequestMessage(HttpMethod.Post, "/some/endpoint");
        using (var requestContent = new StreamContent(stream))
        {
            request.Content = requestContent;
            using (var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead))
            {
                response.EnsureSuccessStatusCode();
                var content = await response.Content.ReadAsStreamAsync();
            }    
        }