18 Feb 2020

Move files around on Forge

Forge has various storage services: Object Storage Service (OSS) for app specific data, and BIM 360 Docs, Fusion Team, etc for user specific data

There are ways to copy files on them, but those are restricted:
- This only works inside the same buckethttps://forge.autodesk.com/en/docs/data/v2/reference/http/buckets-:bucketKey-objects-:objectName-copyto-:newObjectName-PUT/ 
- This only works on BIM 360 Docshttps://forge.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-items-POST/ (using copyFrom URL param)

How could you create a generic solution?

You could use the various Forge API's to download a file and then upload it back to the new location.
If your server has a really fast and unlimited connection then no need to read any further ?

However, if that's not the case (maybe you don't even have a server, but trying to do this from a desktop app) then the following could be a solution.

Note that this also has limitations because of the Design Automation API's Rate limits and Quotas
However, you can reach out to us to increase the quotas within reasonable limits.

The following idea is about using Design Automation API to move files around. In this case the file would not even leave Forge, which should also ensure the fastest transfer time possible.

Since Design Automation API for AutoCAD (DA4A) is the cheapest (see pricing) we could go with that. All we would really need is an Activity that has a "source" parameter for the source file location and a "target" for the target location. 
However, it seems like DA4A needs to run something as part of the process, so I created an empty .NET Console App (using .NET Framework) that does nothing at all when run. 
I just had to package it and upload it as an AppBundle
Here is the zip file: https://github.com/adamenagy/CopyBetweenFolders/blob/master/EmptyExe.bundle.zip

I named the AppBundle "EmptyExe" and created an Activity with the following properties:

{
  "commandLine": [
    "$(appbundles[EmptyExe].path)\\EmptyExe.bundle\\Contents\\empty.exe"
  ],
  "parameters": {
    "source": {
      "verb": "get",
      "description": "",
      "localName": "file.blob"
    },
    "target": {
      "verb": "put",
      "description": "",
      "localName": "file.blob"
    }
  },
  "id": "<my client id>.CopyBetweenBuckets+prod",
  "engine": "Autodesk.AutoCAD+22",
  "appbundles": [
    "<my client id>.EmptyExe+prod"
  ],
  "description": "CopyBetweenBuckets",
  "version": 1
}

Now I can pass the URL of the source file and the URL of the target location to my WorkItem to transfer the files using Design Automation:

{
  "source": {
    "verb": "get",
    "localName": "file.blob",
    "url": "https://developer.api.autodesk.com/oss/v2/buckets/adam_poc/objects/Chain.sat",
    "headers": {
      "Authorization": "Bearer <access token>",
      "Content-type": "application/octet-stream"
    }
  },
  "target": {
    "verb": "put",
    "localName": "file.blob",
    "url": "https://developer.api.autodesk.com/oss/v2/buckets/adam_poc2/objects/Chain.sat",
    "headers": {
      "Authorization": "Bearer <access token>",
      "Content-type": "application/octet-stream"
    }
  }
}

Here is the part of report.txt for the WorkItem showing how the download, running of empty.exe, and the upload succeeded:

[02/18/2020 17:45:49] Starting work item d1002c87d7c743fbb3345995fd9db6f6
[02/18/2020 17:45:49] Start download phase.
[02/18/2020 17:45:49] Start downloading file https://developer.api.autodesk.com/oss/v2/buckets/adam_poc/objects/Chain.sat.
[02/18/2020 17:45:49] Start preparing AppPackage EmptyExe.
[02/18/2020 17:45:49] Download bits and install app to local cache.
[02/18/2020 17:45:49] End downloading file https://developer.api.autodesk.com/oss/v2/buckets/adam_poc/objects/Chain.sat. 1074980 bytes have been written to T:\Aces\Jobs\d1002c87d7c743fbb3345995fd9db6f6\file.blob.
[02/18/2020 17:45:49] End download phase.
[02/18/2020 17:45:49] Start preparing script and command line parameters.
[02/18/2020 17:45:49] Command line: []
[02/18/2020 17:45:49] Identified standalone application at T:\Aces\AcesRoot\22.0\coreEngine\Exe\HostApp.exe.
[02/18/2020 17:45:49] End preparing script and command line parameters.
[02/18/2020 17:45:49] Start script phase.
[02/18/2020 17:45:49] ### Command line arguments: /isolate HKEY_CURRENT_USER\SOFTWARE\AppDataLow\Software\Autodesk\CoreUser\WorkItem_d1002c87d7c743fbb3345995fd9db6f6 "T:\Aces\Jobs\d1002c87d7c743fbb3345995fd9db6f6\userdata" /exe "T:\Aces\AcesRoot\22.0\coreEngine\Exe\HostApp.exe" .
[02/18/2020 17:45:49] Start application HostApp.exe standard output dump.
[02/18/2020 17:45:50] End application HostApp.exe standard output dump.
[02/18/2020 17:45:50] End script phase.
[02/18/2020 17:45:50] Start upload phase.
[02/18/2020 17:45:50] Uploading T:\Aces\Jobs\d1002c87d7c743fbb3345995fd9db6f6\file.blob to https://developer.api.autodesk.com/oss/v2/buckets/adam_poc2/objects/Chain2.sat.
[02/18/2020 17:45:51] End upload phase.
[02/18/2020 17:45:51] Job finished with result Succeeded

Note: the various Design Automation limits apply. So depending on how big the files are you might need to use e.g. Design Automation for Revit.

If you want to move files to BIM 360 Docs but would rather use an existing solution then you could have a look at Cloudsferhttps://www.cloudsfer.com/supported-systems/bim-360/

Related Article