Managing files in Generic File Storage

You can upload, delete, update, and list any project files in the GENERIC FILE STORAGE section of Bitrise.

Table 1. Endpoints related to the Generic File Storage

Creating and uploading files to the Generic File Storage

You can add new files to an application and store it in the GENERIC FILE STORAGE section of the Code Signing tab. When calling the relevant API endpoint, a new temporary pre-signed upload URL is created which you will use to upload the file to the GENERIC FILE STORAGE. (Please note that this pre-signed URL is time-limited and expires after 10 minutes.)

You'll need to:

  1. Call the POST method of the generic-project-files endpoint.

    This call creates a temporary pre-signed upload URL. The required parameters are:

    • app slug

    • generic project file’s metadata: upload file name, upload file size and the user env key (you can add any name to the user env key)

  2. Upload the file to AWS using the pre-signed upload URL.

  3. Confirm the file upload.

    This sets the processed flag to true which means the file is now available on Bitrise. This flag can't be changed again afterwards!

Example 1. Creating and uploading a file

Creating the temporary pre-signed upload URL:

                        curl -X POST "https://api.bitrise.io/v0.1/apps/583806e34b4ff0ff/generic-project-files" -H "accept: application/json" -H "Authorization: 0FgS4dsnxG9sYWp3xh9aLkbUz7BC01ZYJRj3RuhDWssadW7NuqbMhobvIWzk76dxrj6md4AXK16pfwj-i6A-uA" -H "Content-Type: application/json" -d "{ \"upload_file_name\": \"Test-File\", \"upload_file_size\": 4865, \"user_env_key\": \"Test-File\"}"

Response:

{
  "data": {
    "upload_file_name": "Test-File",
    "upload_file_size": 4865,
    "slug": "01D7F228E7N8Q8WQJKJM8FV3XM",
    "processed": false,
    "is_expose": true,
    "is_protected": false,
    "upload_url": "https://concrete-userfiles-production.s3.us-west-2.amazonaws.com/project_file_storage_documents/uploads/24043/original/Test-File?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAIV2YZWMVCNWNR2HA%2F20190402%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20190402T125827Z&X-Amz-Expires=600&X-Amz-SignedHeaders=content-length%3Bhost&X-Amz-Signature=e1557901d5a07b1b3578d9ffdf84a9b0188b742bfff9c8175a3e87f12c7e2c4e",
    "user_env_key": "Test-File",
    "exposed_meta_datastore": null
  }
}

Uploading the file to AWS:

                        curl -T Test-File.md "https://concrete-userfiles-production.s3.us-west-2.amazonaws.com/project_file_storage_documents/uploads/24043/original/Test-File?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAIV2YZWMVCNWNR2HA%2F20190402%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20190402T125827Z&X-Amz-Expires=600&X-Amz-SignedHeaders=content-length%3Bhost&X-Amz-Signature=e1557901d5a07b1b3578d9ffdf84a9b0188b742bfff9c8175a3e87f12c7e2c4e"

Confirming the file upload:

curl -X POST -H 'Authorization: THE-ACCESS-TOKEN' 'https://api.bitrise.io/v0.1/apps/APP-SLUG/generic-project-files/GENERIC-PROJECT-FILES-SLUG/uploaded'

Response:

{
  "data": {
    "upload_file_name": "Test-File",
    "upload_file_size": 4865,
    "slug": "01D7F228E7N8Q8WQJKJM8FV3XM",
    "processed": true,
    "is_expose": true,
    "is_protected": false,
    "user_env_key": "Test-File",
    "exposed_meta_datastore": null
  }
}

Updating an uploaded file

You can perform minor updates to an uploaded file using the PATCH method of the generic-project-files endpoint. If you’ve uploaded your file to Bitrise, you can visually check the changes in the Generic File Storage.

The required parameters are:

  • app slug

  • generic project file slug

  • generic project file attributes you wish to modify

For example, to make the uploaded file protected, you can set the is_protected flag of your file to true.

curl -X PATCH -H 'Authorization: THE-ACCESS-TOKEN' 'https://api.bitrise.io/v0.1/apps/APP-SLUG/generic-project-file/GENERIC-PROJECT-FILE-SLUG -d '{"is_protected":true}'

Be careful when setting attributes

You can set the is_protected, is_exposed and processed attributes of the files you've uploaded:

  • Once the is_protected flag is set to true, it cannot be changed anymore.

  • When the value of is_protected is true, then the is_expose flag cannot be set to another value.

  • Once the processed flag is set to true, then its value cannot be changed anymore.

Retrieving a specific file's data

Retrieve a specific file’s data from the Generic File Storage with the GET method of the generic-project-files endpoint. The returned data includes, among other things, the file's name, size, and download URL, as well as its current status.

The required parameters are:

  • app slug

  • generic project file slug

Example 1. Retrieving a file

Request:

 curl -X GET -H  'Authorization: THE-ACCESS-TOKEN' 'https://api.bitrise.io/v0.1/apps/APP-SLUG/generic-project-files/GENERIC-PROJECT-FILE-SLUG'

Response:

{
  "data": {
    "upload_file_name": "Test-File",
    "upload_file_size": 4865,
    "slug": "01D7F228E7N8Q8WQJKJM8FV3XM",
    "processed": true,
    "is_expose": true,
    "is_protected": false,
    "download_url": "https://concrete-userfiles-production.s3.us-west-2.amazonaws.com/project_file_storage_documents/uploads/24043/original/Test-File?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAIV2YZWMVCNWNR2HA%2F20190402%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20190402T132712Z&X-Amz-Expires=600&X-Amz-SignedHeaders=host&X-Amz-Signature=241be52184b63867262360743931c546c166a99719787ce417e3be11bc12bbed",
    "user_env_key": "Test-File",
    "exposed_meta_datastore": null
  }
}

Availability of the download_url

Note that the download_url is generated only when the provisioning profile’s is_protected attribute is false.


Listing the uploaded files of an app

Get a list of an app's files that were uploaded to the Generic File Storage using the GET method. Please note that the maximum number of files is 50.

The required parameter is:

  • app slug

Optional parameters are:

  • next: slug of the first file in the response (as a string)

  • limit: max number of elements per page (as an integer)

Example 1. Listing the apps

Request:

curl -X GET -H 'Authorization: THE-ACCESS-TOKEN' 'https://api.bitrise.io/v0.1/apps/APP-SLUG/generic-project-files'

Response:


{
  "data": [
    {
      "upload_file_name": "realmtasks.jks",
      "upload_file_size": 2068,
      "slug": "a37f6a0ff582f4ea",
      "processed": true,
      "is_expose": true,
      "is_protected": false,
      "user_env_key": "ANDROID_KEYSTORE",
      "exposed_meta_datastore": null
    },
    {
      "upload_file_name": "Test-File",
      "upload_file_size": 4865,
      "slug": "01D7F228E7N8Q8WQJKJM8FV3XM",
      "processed": true,
      "is_expose": true,
      "is_protected": false,
      "user_env_key": "Test-File",
      "exposed_meta_datastore": null
    }
  ],
  "paging": {
    "total_item_count": 2,
    "page_item_limit": 50
  }
}

As you can see, the example response shows the list of files specific to an app. Files uploaded to the ANDROID KEYSTORE SECTION and to the GENERIC FILE STORAGE are both shown. This is due to that the fact that Android keystore files are specific generic project files but represented in a separate UI field from generic project files.

Deleting a file from the Generic File Storage

You can delete your uploaded file from the Generic File Storage using the DELETE method.

The required parameters are:

  • app slug

  • generic project file slug

curl -X DELETE “https://api.bitrise.io/v0.1/apps/{app-slug}/generic-project-files/{generic-project-file-slug}” -H “Authorization:{Authorization-token}”