Upload from a URL
Let BIM.works download a model straight from cloud storage with a pass-through URL, and when to download it yourself instead.
For a backend whose models live in S3, Azure Blob Storage or another store reachable by URL. Instead of moving the bytes through your server twice, hand the URL to BIM.works and let the repository fetch the file itself. The Java SDK also offers the opposite: download the file to a temporary location and upload it as usual.
Before you start#
- A login with the
model:uploadscope and write rights on the target folder. - A URL that the BIM.works server can use: its host resolves and routes from the server (not only from your machine), and it carries its own authorisation, a pre-signed URL on S3 or a shared access signature on Azure.
- The file name, which usually cannot be read from such a URL, and the file size in bytes, which the storage service may not send in a
Content-Lengthheader.
1. Pass the URL through#
import java.net.URI;
import java.net.URL;
import nl.bimbase.bimworks.client.UploadModelResponse;
import nl.bimbase.bimworks.client.upload.UploadBuilder;
URL url = URI.create("https://bucket.s3.eu-west-1.amazonaws.com/house.ifc?X-Amz-Signature=...").toURL();
UploadModelResponse response = client.upload.uploadModel(
new UploadBuilder(folderUuid).urlPassThrough(url, 52_428_800L).filename("house.ifc"));
UUID versionUuid = response.getNewVersionUuid();UploadBuilder builder = new UploadBuilder(folderUuid)
.PassThrough(new Uri("https://bucket.s3.eu-west-1.amazonaws.com/house.ifc?X-Amz-Signature=..."), 52428800L);
builder.filename = "house.ifc";
UploadResponse response = client.Upload.UploadModel(builder).GetUploadResponse();
Guid versionUuid = response.treeNode.GetLastVersion().Uuid;import nl.bimbase.bimworks.sdk.api.AuthApi;
import nl.bimbase.bimworks.sdk.api.ModelApi;
import nl.bimbase.bimworks.sdk.client.ApiClient;
import nl.bimbase.bimworks.sdk.model.AddModelWithUrlRequest;
import nl.bimbase.bimworks.sdk.model.Auth;
import nl.bimbase.bimworks.sdk.model.LoginWithApiTokenRequest;
public class Example {
public static void main(String[] args) throws Exception {
// 1. Connect to BIM.works and log in with your API token
ApiClient client = new ApiClient();
client.updateBaseUri("https://bim.works/openapi");
Auth auth = new AuthApi(client)
.loginWithApiToken(new LoginWithApiTokenRequest().token("<your API token>"))
.getAuth();
client.setRequestInterceptor(builder -> builder.setHeader("Authorization", "Bearer " + auth.getBase64()));
// 2. The request
AddModelWithUrlRequest request = client.getObjectMapper().readValue("""
{
"node_uuid": "<folder uuid>",
"filename": "house.ifc",
"url": "https://bucket.s3.eu-west-1.amazonaws.com/house.ifc?X-Amz-Signature=..."
}
""", AddModelWithUrlRequest.class);
// 3. The call
var result = new ModelApi(client).addModelWithUrl(request);
// 4. The result
System.out.println(client.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(result));
}
}using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;
// 1. Connect to BIM.works and log in with your API token
IServiceProvider Connect(string bearer)
{
var services = new ServiceCollection();
services.AddApi(options =>
{
options.AddTokens(new BearerToken(bearer));
options.AddApiHttpClients(http =>
{
http.BaseAddress = new Uri("https://bim.works" + "/openapi");
http.Timeout = Timeout.InfiniteTimeSpan;
});
});
return services.BuildServiceProvider();
}
var login = await Connect("").GetRequiredService<IAuthApi>().LoginWithApiTokenAsync(new LoginWithApiTokenRequest("<your API token>"));
var auth = login.Ok()?.Auth ?? throw new HttpRequestException(login.RawContent, null, login.StatusCode);
var client = Connect(auth.Base64);
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;
// 2. The request
var request = JsonSerializer.Deserialize<AddModelWithUrlRequest>("""
{
"node_uuid": "<folder uuid>",
"filename": "house.ifc",
"url": "https://bucket.s3.eu-west-1.amazonaws.com/house.ifc?X-Amz-Signature=..."
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IModelApi>().AddModelWithUrlAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result, json));import { AddModelWithUrlRequestFromJSON, AuthApi, Configuration, ModelApi, ModelVersionToJSON } from "@bimworks/sdk";
// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
.loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });
// 2. The request
const request = AddModelWithUrlRequestFromJSON({
"node_uuid": "<folder uuid>",
"filename": "house.ifc",
"url": "https://bucket.s3.eu-west-1.amazonaws.com/house.ifc?X-Amz-Signature=..."
});
// 3. The call
const result = await new ModelApi(client).addModelWithUrl({ addModelWithUrlRequest: request });
// 4. The result
console.log(JSON.stringify(ModelVersionToJSON(result), null, 2));<?php
require __DIR__ . '/vendor/autoload.php';
use BIMworks\Api\AuthApi;
use BIMworks\Api\ModelApi;
use BIMworks\Configuration;
use BIMworks\Model\AddModelWithUrlRequest;
use BIMworks\Model\LoginWithApiTokenRequest;
use BIMworks\ObjectSerializer;
// 1. Connect to BIM.works and log in with your API token
$client = (new Configuration())->setHost('https://bim.works/openapi');
$auth = (new AuthApi(config: $client))->loginWithApiToken(new LoginWithApiTokenRequest(['token' => "<your API token>"]));
$client->setAccessToken($auth->getBase64());
// 2. The request
$request = ObjectSerializer::deserialize(<<<'JSON'
{
"node_uuid": "<folder uuid>",
"filename": "house.ifc",
"url": "https://bucket.s3.eu-west-1.amazonaws.com/house.ifc?X-Amz-Signature=..."
}
JSON, AddModelWithUrlRequest::class);
// 3. The call
$result = (new ModelApi(config: $client))->addModelWithUrl($request);
// 4. The result
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;import json
import bimworks
# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64
# 2. The request
request = bimworks.AddModelWithUrlRequest.from_json(r"""
{
"node_uuid": "<folder uuid>",
"filename": "house.ifc",
"url": "https://bucket.s3.eu-west-1.amazonaws.com/house.ifc?X-Amz-Signature=..."
}
""")
# 3. The call
result = bimworks.ModelApi(client).add_model_with_url(request)
# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))The builder methods are UploadBuilder.urlPassThrough(URL, long) and filename in Java (UploadApi) and UploadBuilder.PassThrough(Uri, long) in .NET (Upload); PHP calls ModelApi::addModelWithUrl (PHP SDK). Over HTTP the operation is AddModelWithUrl; it needs no size, blocks until the model is checked in and answers with the new version:
Bearer <auth token>application/jsonAuthorization: Bearer <auth token>
Content-Type: application/json
Accept: application/jsoncurl -X POST "$BIMWORKS_URL/openapi/model/AddModelWithUrl" \
-H "Authorization: Bearer $BIMWORKS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"node_uuid": "<folder uuid>",
"filename": "house.ifc",
"url": "https://bucket.s3.eu-west-1.amazonaws.com/house.ifc?X-Amz-Signature=..."
}'The server waits up to an hour for the download and another for the check-in, but the reverse proxy of a standard installation stops waiting after ten minutes (proxy_read_timeout 600s) and answers 504 with REQUEST_TIMED_OUT while the server carries on. The model node is created before the download starts, so look it up by its path in the target folder (GetNode with path): its tree_node_status becomes DONE once the version is checked in, with the new version in last_version_uuid, or ERROR when the check-in fails, with the reason in errors.
path may replace node_uuid: the target node's path below the root node of the credential (/Projects/House), answered with NODE_NOT_FOUND when nothing is there. Without either the model lands in the root node of the credential. input_file_type overrides the type derived from the file name, which is the way to upload from an extension-less URL.
The JavaScript SDK's upload.uploadFromUrl(url, filename, nodeUuid) (Upload) is not a pass-through: the browser fetches the URL itself and uploads the bytes, so the URL must be readable from the page (same origin or CORS-enabled), and an HTTP error rejects the call instead of uploading the error page. Use it for files that are already next to your page, not for cloud storage.
2. Or download first, then upload#
When the URL is reachable from your server but not from BIM.works (an internal file server), let the SDK fetch it. Java's UploadBuilder.url(URL) downloads to a temporary file and uploads that, with the usual deduplication (Upload a model); the file passes through your machine and needs disk space for the whole model.
UploadModelResponse response = client.upload.uploadModel(
new UploadBuilder(folderUuid).url(URI.create("https://files.internal/house.ifc").toURL()).filename("house.ifc"));3. Read the errors#
A pass-through fails on the server side, so the errors name what the server saw: INVALID_URL for a URL it cannot parse, UPLOAD_URL_CANNOT_RESOLVE_DNS and UPLOAD_URL_NO_ROUTE_TO_HOST for a host it cannot reach, UPLOAD_URL_NOT_AUTHORIZED when the storage answers 401 or 403 (missing credentials, or a signature that has expired) and UPLOAD_URL_NOT_FOUND when it answers 404. A URL on a private, loopback or link-local address is refused before anything is fetched, UPLOAD_URL_REFUSED, unless the instance lists the host in egress.allowed_private_hosts. Any other answer is UNKNOWN_UPLOAD_ERROR. A file that parses badly fails like any other upload.
Check#
The reply carries a new version whose filename is the name you passed; List the tree shows the node in the folder, and a query on the version returns its objects (Run a BQL query).