---
title: Upload a model
summary: Upload a model from a file or a stream into a folder, follow the progress, and find the version it created.
order: 10
languages: [javascript, java, csharp, php]
terms: [node, version, streaming-upload, api-token]
see-also: [how-to/models/upload-from-a-url, how-to/models/list-the-tree, how-to/models/create-a-folder, reference/file-types, how-to/using-bimworks/upload-in-the-ui, tutorials/openapi/getting-started]
---

# Upload a model

For an application that puts models into BIM.works. An upload targets a folder [[term:node|node]]: a file whose name is new in the folder creates a model node with version 1, a file with the name of an existing model node adds the next [[term:version|version]] to it. The reply is the node with its new `last_version_uuid`, the id the queries and viewers use.

## Before you start

- A login whose credential has the `model:upload` scope and write rights on the folder ([[page:how-to/auth/log-in-with-an-api-token]]).
- The folder's UUID. The root node of the credential is a fine start: `fs.getRootNodeUuid()`; a folder by path: [[page:how-to/models/list-the-tree]].
- A file of a supported type, [[filetype:IFC]] and the others in [[page:reference/file-types]].

## 1. Upload from a file

```code-group {#file} classic
```javascript
// Browser: a File from an <input type="file"> or a drop event
const folderUuid = await client.fs.getRootNodeUuid();
const upload = await client.upload.createUploadFromFile(file, folderUuid);
upload.setProgressHandler((label, percentage) => console.log(label, percentage));
upload.setErrorHandler((error) => console.error(error));
const result = await upload.start();
console.log(result.node.last_version_uuid);

// Node.js: a path instead of a File
const nodeUpload = await client.upload.createUploadFromFileName("models/house.ifc", folderUuid);
const nodeResult = await nodeUpload.start();
```
```java
import java.nio.file.Paths;
import java.util.UUID;
import nl.bimbase.bimworks.client.UploadModelResponse;
import nl.bimbase.bimworks.client.upload.UploadBuilder;

UUID folderUuid = client.fs.getRootNodeUuid();
UploadModelResponse response = client.upload.uploadModel(
		new UploadBuilder(folderUuid).fromPath(Paths.get("models/house.ifc")));
UUID versionUuid = response.getNewVersionUuid();
```
```csharp
using System.IO;

Guid folderUuid = client.Fs.GetRootNodeUuid();
AsyncUploadTask task = client.Upload.UploadModel(new UploadBuilder(folderUuid).SetPath(@"models\house.ifc"));
UploadResponse response = task.GetUploadResponse();   // blocks until the checkin is done
Guid versionUuid = response.treeNode.GetLastVersion().Uuid;
```
```

```sdk-example
operation: UploadModel
```

The methods: `createUploadFromFile`/`createUploadFromFileName` on [[js:@bimworks/jssdk/Upload|Upload]], `UploadApi.uploadModel` with an `UploadBuilder` on [[java:nl.bimbase.bimworks.client.apis.UploadApi|UploadApi]], `Upload.UploadModel` with an `UploadBuilder` on [[dotnet:BIM.works_SDK.Upload|Upload]], `ModelApi::uploadModel` in [[page:reference/sdk/php]]. Over HTTP the operation is [[openapi:UploadModel]], a `multipart/form-data` request whose reply is the new version:

```try-it
operation: UploadModel
method: POST
path: /openapi/model/UploadModel
```

Without `node_uuid` the upload goes to the root node of the credential. `input_file_type` overrides the type derived from the file name (for a misnamed file); `format_settings` carries point-cloud options. `tags` (comma-separated, `DEMO`), `validation_settings` (a JSON object) and `force_reprocessing` are the SDK builders' options.

Over HTTP, two fields replace what the SDKs do for you:

- **`hash` instead of the file.** Ask [[openapi:LookupModelHashes]] first: with the size and the xxh64 of the first 32 KiB, then for a known file with the xxh64 of the whole file (seed 18497208744731555, as an unsigned decimal string). When the server knows the file, send its `hash` and the `filename` without a `file` part: no bytes travel. A hash the server cannot use answers [[error:DefaultErrorCode.NO_STREAM]] (404) before anything is created; send the file then.
- **`wait_ms` instead of waiting.** The call answers the version when the checkin ends within that many milliseconds, and otherwise `202` with the checkin's status and `job_uuid`. Follow it with [[openapi:GetCheckin]], which waits up to `wait_ms` itself (at most 5 minutes) and holds the version once the status is `DONE`, or the error once it is `FAILED`. A ZIP of models has no job and is always waited for.

## 2. Or upload from a stream

When the model is not on disk (it comes from a request, a database, another service), pass the stream and its size. The SDK sends the bytes as they arrive; the size is needed for the deduplication check below.

```code-group {#stream}
```javascript
// Browser or Node.js: an ArrayBuffer you already have
const upload = await client.upload.createUploadFromArrayBuffer(arrayBuffer, "house.ifc", folderUuid);
const result = await upload.start();
```
```java
try (InputStream in = source.openStream()) {
	UploadModelResponse response = client.upload.uploadModel(
			new UploadBuilder(folderUuid).fromInputStream(in, size).filename("house.ifc"));
}
```
```csharp
UploadBuilder builder = new UploadBuilder(folderUuid);
builder.stream = File.OpenRead(path);
builder.filename = "house.ifc";
builder.filesize = new FileInfo(path).Length;
UploadResponse response = client.Upload.UploadModel(builder).GetUploadResponse();
```
```

## 3. Understand what happens

- **Deduplication.** Before sending, the SDK hashes the first 32 KB (xxh64) and asks whether the server already has a file of that size and prefix; if so it hashes the whole file and, on a full match, the server reuses the stored file and only the node and version are created. This is why uploading the same file twice is fast and why the size must be right. The Java builder's `forceReprocessing(true)` skips the check and reprocesses.
- **Same name, new version.** A file whose name exists in the folder as a model node becomes that node's next version; uploading straight onto a model node does the same.
- **Processing.** The call returns when the model is checked in: parsed, indexed, geometry generated. Large models take minutes; the Java builder's timeout defaults to four hours, the JavaScript upload's to eight. Progress arrives through the handler (JavaScript), a `ProgressListener` on the builder (Java) or `AddProgressListener` on the task (.NET).
- **Failures.** A file the parser rejects ends with the version in an error state and an error node on the node; the reasons are the error codes listed under [[page:reference/errors#StepParserErrorCode|StepParserErrorCode]] and [[page:reference/errors#BimWorksErrorCode|BimWorksErrorCode]] in [[page:reference/errors]]. A missing scope fails with [[error:NON_AUTHORIZED_SCOPE]], a missing write right with [[error:AuthorizationError.NO_WRITE_RIGHTS]].

## Check

List the folder ([[page:how-to/models/list-the-tree]]): the model node is there, its `last_version_uuid` equals the one from the reply, and its `versions` array has grown by one. Run a query on the new version ([[page:how-to/query/run-a-bql-query]]): `GET type, COUNT(qid) GROUP BY type` returns the object types of the file.
