ImageGear v26.5 - Updated
Developer Guide / How to Work with ... / REST APIs / Use Work Files
In This Topic
    Use Work Files
    In This Topic

    To use the ImageGear REST APIs to process your files, first upload files to the Accusoft Cloud. Files uploaded in this way are referred to as work files, and are temporarily stored for further processing. Furthermore, successful requests to the ImageGear REST API will produce new work files that can then be downloaded via another request to the work file API.

    Uploading Work Files

    To upload a work file, post the image file to the /PCCIS/V1/WorkFile endpoint at https://api.accusoft.com. You will need to provide an Accusoft Cloud API Key in order to upload work files. For image files, you should always provide file extension as a request parameter, and you should also explicitly set the content type of your request as application/octet-stream.

    C#

    var client = new HttpClient();
    client.BaseAddress = new Uri( @"https://api.accusoft.com");
    client.DefaultRequestHeaders.Add("acs-api-key", "YourAPIKey"); // <-- API Key Here
    
    // Upload image
    var content = new StreamContent(File.OpenRead(@"./yourimage.bmp")); // <-- Image path here
    content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/octet-stream");
    var response = await client.PostAsync(@"/PCCIS/V1/WorkFile?FileExtension=bmp", content);
    

    Receiving a 200 status code back from the work file service indicates that your file has been successfully uploaded, and a JSON response body will be sent back which provides you with important information about the work file that you will need for subsequent requests to Accusoft's Cloud APIs which work with your uploaded images:

    JSON

    {
        "fileId": "Xe6zv3dH0kVSzLuaNhd32A",
        "fileExtension": "bmp",
        "affinityToken": "ejN9/kXEYOuken4Pb9ic9hqJK45XIad9LQNgCgQ+BkM="
    }
    
    • fileId is the unique id of the new work file resource, often used later as input to a viewing session or process.

    Downloading Work Files

    Completed requests to the REST API will include a JSON output object which provides a fileId property to return the identifier for the output image:

    JSON

    HTTP 200 OK
    Content-Type: application/json
    {
      "input": {
        "source": {
          "fileId": "ek5Zb123oYHSUEVx1bUrVQ"
        }
      },
      "processId": "iFhSZRvrz2vtFjcTSi9Qlg",
      "expirationDateTime": "2019-02-05T13:24:35.395Z",
      "state": "complete",
      "output": {
        "fileId": "fl6Ac234pZITVFWy2cVsWR"
      }
    }
    

    The fileId from this object can then be passed back to the Work File API to retrieve the output image:

    C#

    HttpResponseMessage downloadRequest = await client.GetAsync(@"/PCCIS/V1/WorkFile/" + outputWorkfileId);
    using (var filestream = new FileStream(outputWorkfileId + ".bmp", FileMode.Create))
    {
        await downloadRequest.Content.CopyToAsync(filestream);
    }
    

    For more information see the Work File API Reference.