Using SDK's and API's to interact with Speckle Server - Uploading files

Hello,

After one week studying Speckle I have 3 main questions.

If my team decide to use Speckle (we are mainly C# devs), it will be from developer perspective, this means, we will have Speckle Server deployed in AWS for example and then, using your SDK’s we will interact with the server through API’s (rest or graphql).

First question:

We will need to upload files to Speckle Server. From my investigation, the front end supports IFC, OBJ or STL. Let’s assume we want to send IFC files to Speckle Server. How can we do it using API’s?

I tried to answer this question here in the community but I did not found a satisfactory response. The docs also do not help here.

I analyzed how the front end is doing this. It uses /api/file/autodetect endpoint, the ifc file will be sent via post. Then the front end uses graphql to query the upload status.


Second question:

So we need to send files that have different formats (eg Revit, AutoCad) to Speckle Server. But we need to do this using your SDK’s. This is possible? I start to think this is not possible. Because your connectors only work in the host application (eg Revit, AutoCad).

This means we will have to use a third party framework that converts file formats to, let say IFC and then use your API’s to send it to Speckle Server (assuming we can answer the first question).

Third question:

We have our data in Speckle but now we need to consume/read it. We may also need to export it, let say, to IFC. Currently Speckle does not support exporting to IFC.

How we can do that? Or we are forced to use Speckle object model here? Do you support exporting to some format? Example, is it possible using SDK’s, to read the data from Speckle and convert it to some format?

Regards,

Alberto

Hello,
relating to the first question, sending an .obj, .stl or .ifc file to Speckle Server, this is possible:

public async Task SendStlFileToSpeckleServer(string pathToIfcFile, string fileName, string streamId)
{

        var requestUri = $"{Account.serverInfo.url}api/file/autodetect/{streamId}/main";

        using (var multipartFormContent = new MultipartFormDataContent())
        {
            var fileStreamContent = new StreamContent(File.OpenRead(pathToIfcFile));
            fileStreamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");

            multipartFormContent.Add(fileStreamContent, name: "file", fileName: fileName);

            var response = await HttpClient.PostAsync(requestUri, multipartFormContent);

            if (response.StatusCode == System.Net.HttpStatusCode.Created)
            {
                Console.WriteLine("SendStlFileToSpeckleServer - OK, file was uploaded to speckle server.");

                return "OK";
            }
            else if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                Console.WriteLine($"SendStlFileToSpeckleServer - NOK, file was not uploaded to speckle server. StatusCode: {response.StatusCode}");

                return "NOK";
            }
            else
            {
                return $"SendStlFileToSpeckleServer - NOK, file was not uploaded to speckle server. StatusCode: {response.StatusCode}";
            }
        }
    }

Regards,
Alberto

Hey Alberto,

Thanks for the good questions and for digging deep in Speckle-land :slight_smile:

Q1

@gjedlicska and @fabians might help figure out which endpoints to use for the IFC upload

Q2

I’m afraid there’s a core difference between your needs and Speckle, you’d like to handle files but Spekcle is designed to work with data. So your assumptions are correct, we do not provide ways to send Revit, Rhino files etc to the server, we only support sending data from their respective Connectors.

Q3

It is possible to download the original IFCs from our API, but as mentioned above, Speckle is designed to work with data and we provide various API endpoints and SDKs to access it programmatically.

My question back to you would be, why do you really need files?

It might sound like a limitation at first, but working with data opens the door to many more possibilities:

  • versioning is handled outside of the box
  • easier sharing and permission management
  • centralized information
  • granular access to each model element via API (eg you can just get the wind turbine out of this model, in your browser)
  • faster and more transparent access
1 Like

Hello @teocomi,
thank you for your reply.

Q1 - I already did that, I found the endpoint :slight_smile: Its working with your free server https://speckle.xyz/. Not working for a local server installed on my windows 10 machine, even if I upload the files using the front end.

Q2 - This means that, if we want to store the file data in Speckle server, let say a Revit file, we need to use a third party library that convert it to, let say IFC and then we use your endpoint to send the file data to the server.

Q3 - why do you really need files? Well, for specific workflows the customer will want to export their data to a file but its not critical.

What is critical is, and I did not investigated this well, we need to send speckle data to a web browser viewer. Or to a server viewer because of the complexity of the file, we want to do the rendering in the server side (SSR). Let say we buy this viewer to a company or we built it in our own.

I think this component will impose some format for the data that it receives for rendering purposes.

I did not investigated the viewer that Speckle uses. This is why I asked if there are some form of, reading Speckle data from the server and convert it to a format X, then we send it to the viewer. Even if we then, need to use a third party library to convert it to Y, let say AutoCad format or Revit, because its a format that the component that does the rendering, accepts.

To be honest, I am only starting investigating this part related to viewer’s.

Regards,
Alberto

Given that the :speckle:Speckle web frontend is a threejs viewer and the SpeckleLoader does that transformation for you into that format, you could take a look at headless SSR possibilities. SSR - Three.js Tutorials

  1. Your server will benefit from having (need) GPU(s).
  2. You are pretty hands-free concerning scene setup.

An alternative could be to use Blender on the server and choreograph with the Python API to set up scenes and manage renders and distribution. I have done this as a short-lived R&D project, but I don’t know if the SpeckleBlender plugin could be triggered by a script or if you’d be better off forking the Plugin and tweaking it to your needs.

If you are self-hosting, or even if not, you may be better off with a different off-the-shelf file storage solution and handle the cross-referencing either in the metadata or some other Key:Value store.

Happy to jump on a quick call to clarify things even more :slight_smile:, just DM me