Batched createFileAsset


(Mark Graham) #1

Hello all,

I’m trying to develop a system where users can upload files and have them associated to thier account using some metadata.

To achieve this, i’m using the JS API, along with the following batched funcitons:

  • createFileAsset
  • acquireLock
  • updateFileAssetContent
  • setMetadata

However, it appears as though the return value of createFileAsset isn’t a very usable format:
{3445: "New File Asset (#3445) 'Bats-3.pdf' of type_code 'pdf_file' created successfully"}
This means that i cannot use the obligatory "%" + "results_0_id" + "%" in subsequent batched requests.

Any suggestions?

Thanks,
Mark Graham


(John gill) #2

I can’t think of any good solutions.

That caveat aside, you could set up your batch to:

  • Create a Folder
  • Create a File asset in that Folder
  • Get the children of the Folder
  • Use the response from getChildren to find the assetid of the FIle
  • Extra credit - you could then move the File asset and delete the Folder asset

It actually works, but that doesn’t make it a good idea.

js_api.batchRequest({
  "functions":{
    "0":{
      "function":"createAsset",
      "args":{
        "parent_id":"210",
        "levels":1,
        "type_code":"folder",
        "asset_name": "Temporary",
        "link_type ":1
      },
      "blocking":1
    },
    "1":{
      "function":"createFileAsset",
      "args":{
        "parent_id":"%results_0_id%",
        "levels":1,
        "type_code":"pdf_file",
        "friendly_name": "Temporary-File.pdf",
        "link_type ":1
      },
      "blocking":1
    },
    "2":{
      "function":"getChildren",
      "args":{
        "asset_id":"%results_0_id%",
        "levels":1,
        "type_codes":"pdf_file",
      }
    },
    "3":{
      "function":"getAttributes",
      "args":{
        "asset_id":"%results_2_0_id%",
      }
    }
  }
}); 

:man_shrugging: