Hi Speckle Teams,
thanks a lot for creating this cool software.
I am not quite sure if I am asking this correctly, as I am new to speckle, but I would like to achieve the following:
I have an IFC file, which I would like to add to my stream - but not via the UI, but programmatically.
I know that Speckle offers an easy way to upload an IFC file via the Frontend, and this works fine.
Now I would like to do the same thing, but in my C# code. E.g. by either using one of the provided REST (or GraphQL) endpoints, or (even better) via some method offered somewhere in your packages or your speckle-sharp project.
I read in another community topic that there is already a REST endpoint that should be able to accept IFC files. So I tried the following
var requestUri = $"https://speckle.xyz/api/file/autodetect/d534066acf/main";
using (var multipartFormContent = new MultipartFormDataContent()) {
var fileStreamContent = new StreamContent(File.OpenRead(@"HOTEL_archi.ifc"));
fileStreamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
multipartFormContent.Add(fileStreamContent, name: "file", fileName: @"HOTEL_archi.ifc");
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Authorization", "Bearer 03e_TOKENINSERTEDHERE");
var response = client.PostAsync(requestUri, multipartFormContent).GetAwaiter().GetResult();
if (response.StatusCode == System.Net.HttpStatusCode.Created) {
Console.WriteLine("OK, file was uploaded to speckle server.");
} else {
Console.WriteLine($"Error, file was not uploaded to speckle server. StatusCode: {response.StatusCode}");
}
}
Unfortunately, when I execute this code, I get a “FORBIDDEN” as response from the server.
I wasn’t able to find an endpoint for an IFC upload in the docs, so I am not quite sure if this is possible at all. And I wasn’t able to really figure out how the authorization token should look like exactly. Perhaps some more header is also missing in the request (e.g. User-Agent or stuff like this?)
Could you please advise me here, what the best way would be to upload an IFC file?
Thanks in advance,
Andreas