Docs / Files and exports

Guides

Files and exports

Send drawings, photos and CAD files to a project's folder, and get STEP, STL, DXF and drawings back.

Each project has one folder of files. You upload files to it, and Ragnar writes the files of its work to it. The app's Files panel shows the same folder.

Upload a file

Send the file's bytes as the request body. Ragnar takes any kind of file up to 500 MiB: STEP and other CAD files, drawings, photos, PDFs.

Terminal
curl --data-binary @motor.step \
  "$RAGNAR_API/v1/files?project_id=<project_id>&name=motor.step" \
  -H "Authorization: Bearer $RAGNAR_API_KEY" \
  -H "Content-Type: model/step"

project_idstring
The project whose folder gets the file. You need edit access to it.
namestring, 1 to 255 characters
The file's name, with any extension. Not blank, and without /, \ or control characters. Encode it for a URL, and write + as %2B.
Content-Typeoptional header
The file's type as type/subtype, up to 200 characters, such as model/step. Without one, Ragnar records application/octet-stream. curl's default for --data-binary, application/x-www-form-urlencoded, is not recorded.
Idempotency-Keyoptional header
Makes a retry safe. A retry with the same key, project_id, name, Content-Type and bytes returns the first file, and skips the pieces already stored.

The file is in the folder as soon as the request returns 201, and you can name it in a message at once.

  • Send the raw bytes. A form upload (multipart/form-data) or a body with a Content-Encoding gets 415 UNSUPPORTED_MEDIA_TYPE.
  • Large files. curl --data-binary reads the whole file into memory first; curl -T motor.step -X POST sends it from disk. Ragnar cuts a body still arriving after 5 minutes, so the largest file needs 14 Mbit/s or more.
  • Retry with a key. Send an Idempotency-Key with a large file. If the upload is cut, send the same request again: the same key, project_id, name, Content-Type and bytes. Ragnar skips the pieces it already has. An unfinished upload expires an hour after its first try, or six hours for a file above 32 MiB. A retry soon after that gets 410 UPLOAD_EXPIRED; send the file again with a new key.
  • Images. Ragnar also keeps a copy its builder can see of each JPEG, PNG, WebP, GIF, AVIF or SVG image up to 100 megapixels. The original stays as you sent it. HEIC photos get no copy: convert them to JPEG first.

Use files in a message

Name up to 64 files in a message's files, by id:

Message body
{ "text": "Make a lid for this box.", "files": [{ "id": "<file_id>" }] }

A message can name only files that are in the folder now. One message can name a file name only once, whatever its case, so take ids from the folder or from earlier messages rather than names.

A file's bytes never change: a new version is a new file with a new id. Many of your uploads can have the same name. When Ragnar writes a file, its own older file of exactly the same name leaves the folder, and so does a file its builder removes; your uploads stay. A file that left still downloads by its id, but a message can no longer name it. Someone can rename a file in Ragnar.

List the folder

Terminal
curl "$RAGNAR_API/v1/files?project_id=<project_id>" \
  -H "Authorization: Bearer $RAGNAR_API_KEY"

project_idstring
The project whose folder to list.
limitoptional integer, 1 to 100
The most files a page holds. Defaults to 20.
cursoroptional string
The next_cursor of the page before.

The list is newest first: your uploads, drawings and the files Ragnar wrote. A plan Ragnar writes for /plan is not a file in the folder; read it in Ragnar.

idstring
The file's identity. The same id always gives the same bytes: a new version is a new file with a new id.
namestring
The file's name. Many of your uploads can have the same name. Someone can rename a file in Ragnar.
sizenumber or null
The size in bytes, when known.
project_idstring
The project whose folder holds the file.
authorobject
Who put the file there: Ragnar for files its work wrote or fetched from a link, otherwise the person who added it.
created_atstring
When the file was added.

Download a file

Terminal
curl -f "$RAGNAR_API/v1/files/<file_id>/content" \
  -H "Authorization: Bearer $RAGNAR_API_KEY" \
  --output bracket.step

The answer is the file's bytes as a download, with its Content-Type and its name in Content-Disposition. A Read only key can download. HEAD on the same path returns the headers without the bytes.

The answer has no Content-Length, and does not take Range. Compare the bytes you received with the file's size: a download that is cut after it starts still began with 200.

Exports

Ask for exports in plain words, and Ragnar delivers them with its reply: "Make a bracket that fits this motor. Export it as STEP." Its reply's text can hold a link to a ragnar:export address, which is a button in the app. In a reply to a message sent through the API, Ragnar makes the file such a link asks for when it is the whole design as STEP, STL or DXF, and lists it in the reply's files. A link for single parts, a zip or a GLB is a button in the app only. To export the saved design at any time, send a message that is only the command:

Terminal
curl -X POST "$RAGNAR_API/v1/chats/<chat_id>/messages" \
  -H "Authorization: Bearer $RAGNAR_API_KEY" \
  -H "Content-Type: application/json" \
  --data '{"text": "/export step"}'

CommandYou get
/export step (or stp)assembly.step
/export stlassembly.stl
/export dxfassembly.dxf
/export drawing (or drawings, svg)assembly-front.svg, assembly-top.svg, assembly-right.svg and assembly-iso.svg
  • /export exports the whole design from its latest saved model. A build still running is not in it: wait until its task is answered.
  • It runs no build and uses no credits. It works while the project is building or waits for an answer, and it is never taken as the answer to a question. It counts toward the hourly limit of messages that start work. Send it without effort.
  • Its task goes pending, then working while the file is made, then answered. Read the reply with ?after= your message, then download each file in its files. The files appear together, when the export is done.
  • A .dxf of a flat part is its cut profile. A .dxf of a design made only of lines in one plane is those lines. A .dxf of anything else is a drawing of its front, top and right views.
  • When there is no saved model yet, or the format is not one of the above, the task is failed with not_started, and the reply says why.
  • Every export makes new files with new ids.