Uploading Files
Uploading a file
Before checking in a file, the file must be locally accessible to the TACTIC server. This can be simply done by uploading the file to the server.
For javascript, you can reference this javascript library:
<script src="https://portal.southpawtech.com/context/spt_js/upload.js"></script>
To upload a file, you will need to get a file handle. You can do this with a simple input:
<input type="file" name="Choose" onSelect="do_upload( { files: files } )"/>
This library provides a simple "upload_files" function which will set the file to the TACTIC server.
const do_upload = (files) => {
let server = TACTIC.get();
upload_files({
files: files,
server: server,
})
}
Of course, you will usually want to implement this with feedback. You can integrate this upload with a more complex progress meter by passing in the various callbacks as shown below:
const do_upload = (files) => {
let server = TACTIC.get();
upload_files( {
server: server,
files: files,
upload_start: (evt) => {
console.log("start");
},
upload_progress: (evt) => {
let percent = 0;
if (evt.total != 0) {
percent = evt.loaded / evt.total;
}
console.log(percent);
},
upload_failed: (evt) => {
console.log(evt);
alert("Failed to upload");
},
upload_complete: (evt) => {
alert("Upload complete");
}
} )
}
Checking in a file
Once a file has been uploaded, it can be checked in.
let server = TACTIC.get();
let file_name = "foo.jpg"
// Give a name for the asset. Often, this is just the file name
let asset_name = "NewImage"
// First create an asset to check the file into
let data = {
name: asset_name,
status: 'Pending'
}
let asset = server.insert("workflow/asset", data)
// then check-in the file to the asset
let options = {}
let context = ""
let snapshot = server.simple_checkin(asset, context, file_name, options)
Note
The path variable here can be the path of the original file. When uploading a file to TACTIC, the file is held in a temporary location which is specific to the authentication ticket. For the simple case, all that is required is the file name.
Snapshots
When a file is checked into an asset, it creates a snapshot. The snapshot is a version of the checked in asset. The first time a file is checked into an asset, it will be set to version 1. Subsequent check-ins will up version the file.
The snapshot will contain all the information about that version of the file.
let version = snapshot["version"]
aler("version: " + version)
Contexts
You can check in other files to this asset as well. However, calling simple_checkin() will just treat the newly uploaded file as another version, even if the file name is different. This is because TACTIC versions by "context" an not by file name. Each version of a context can be a completely different file.
So, if you want to check in another file that is to be separately versioned, you need to check it in with a different context. The default context if none is specified is "publish".
let file_name = "foo.jpg"
let options = {
name: asset_name,
path: path,
}
let context = "reference"
let snapshot = server.simple_checkin(asset, context, file_name, options)
This will create a version 1 of the context "reference". The previous check-in would have been a version 1 of the context "publish". Both of these context will be independently versioned. This allows you to store any number of different files under a given asset.
Assets and Workflow
Assets can also be associated with a process in the workflow of the job. A job can have a workflow attached to it and while the workflow is executing, it can be desirable to store files in the corresponding process. To do this, an asset could be created under that process.
This is simply done by setting the process attribute to the asset
asset_name = "NewImage"
data = {
"name": asset_name,
"job_code": job_code
"process": "First Process"
}
asset = servier.insert("workflow/asset", data)
Retrieving a file
To get the files from a job, you first have to retrieve the appropriate assets. It is often more convenient to use the TACTIC Expression language
To get all of the assets in a particular process
job_code = "JOB00232"
process = "First"
expr = "@SOBJECT(workflow/asset['job_code','%s']['process','%s'].sthpw/snapshot) % (job_code, process)
snapshots = server.eval(expr)
Retriving a preview
If the files checked in is an image file, it will automatically be processed to create icon that can be used for display in an interface.
Every snapshot can have a number of files associated with it. If the file uploaded is an image, it wil automatically be processes and smaller preview images will be generated.
urls = server.get_all_paths_from_snapshot(snapshot)
Javascript Examples:
For the most part, the code for javascript will be the same as for Python
Storage of Files (Digital Asset Management)
Include a javascript library that uploads files to TACTIC in API
Assets are containers for files. Although it is possible to store any number of files in an assets, most often an asset will represent only one file.
When adding a file to job, first a new asset must be created:
// job_code relates the new asset to its parent job
let job_code = "JOB00232";
let asset_name = "NewImage"
let data = {
name: asset_name,
job_code: job_code
}
let asset = server.insert("workflow/asset", data)
// then check-in the file to the asset
let context = 'Publish'
let options = {}
server.simple_checkin(asset, context, file_path, options)
// Store a file in an asset
let asset = server.get_by_code("workflow/asset", "ASSET012345")
server.simple_checkin(asset, ...)
// retrieve url of file
let server = TACTIC.get();
let snapshot = server.get_snapshot(asset);
// storing multiple files in a single asset
// organizing files in a single asset