Slack.Web.Files (SlackKit v1.0.0-alpha.0)

View Source

Summary

Functions

Finishes an upload started with files.getUploadURLExternal

Gets a URL for an edge external file upload

Gets information about a file.

List files for a team, in a channel, or from a user with applied filters.

Revokes public/external sharing access for a file

Enables a file for public/external sharing.

Uploads or creates a file.

Functions

complete_upload_external(files, optional_params \\ %{})

Finishes an upload started with files.getUploadURLExternal

API reference

Rate limit: Tier 4: 100+ per minute
Scopes:

View on docs.slack.dev ↗

Required Params

  • files - Array of file ids and their corresponding (optional) titles. ex: [{"id":"F044GKUHN9Z", "title":"slack-test", "highlight_type":"png"}]

Optional Params

  • blocks - A JSON-based array of structured rich text blocks, presented as a URL-encoded string. If the initial_comment field is provided, the blocks field is ignored ex: [{"type": "section", "text": {"type": "plain_text", "text": "Hello world"}}]
  • channel_id - Channel ID where the file will be shared. If not specified the file will be private. ex: C0NF841BK
  • channels - Comma-separated string of channel IDs or user IDs where the file will be shared. ex: C0NF841BK,C2AW648GH
  • initial_comment - The message text introducing the file in specified channels.
  • thread_ts - Provide another message's ts value to upload this file as a reply. Never use a reply's ts value; use its parent instead. Also make sure to provide only one channel when using 'thread_ts' ex: 1524523204.000192

Errors the API can return:

  • channel_not_found - Value passed for channel_id was invalid.
  • channels_limit_exceeded - Exceeded the channel limit. A maximum of 100 channels is allowed per request.
  • file_not_found - Could not find the file from the upload ticket.
  • file_type_not_allowed - The file type is not permitted based on the team's allowed_file_upload_types preference.
  • file_update_failed - Failure occurred when attempting to update the file.
  • file_uploads_except_images_disabled - Only image file uploads are permitted for this team.
  • invalid_blocks - Provided blocks are in the incorrect format.
  • invalid_channel - Channel could not be found or channel specified is invalid.
  • not_in_channel - User/bot membership is required for the specified channel.
  • posting_to_channel_denied - User is not authorized to post to channel.

See the Common Errors guide for errors returned by every Web API method.

delete(file, optional_params \\ %{})

Deletes a file.

API reference

Rate limit: Tier 3: 50+ per minute
Scopes:

View on docs.slack.dev ↗

Required Params

  • file - ID of file to delete.

Errors the API can return:

  • cant_delete_file - Authenticated user does not have permission to delete this file.
  • delete_not_allowed - Error returned when the requested file does not support deletion; for example, when attempting to delete a canvas template.
  • file_deleted - The file has already been deleted.
  • file_deleting_disabled - This functionality is disabled.
  • file_not_found - The file does not exist, or is not visible to the calling user.

See the Common Errors guide for errors returned by every Web API method.

get_upload_url_external(filename, length, optional_params \\ %{})

Gets a URL for an edge external file upload

API reference

Rate limit: Tier 4: 100+ per minute
Scopes:

View on docs.slack.dev ↗

Required Params

  • filename - Name of the file being uploaded. ex: laughingoutloudcat.jpg
  • length - Size in bytes of the file being uploaded. ex: 53072

Optional Params

  • alt_txt - Description of image for screen-reader. ex: Aerial view of the Bixby Bridge and coastline of the Big Sur area in California
  • snippet_type - Syntax type of the snippet being uploaded. ex: python

Errors the API can return:

  • alt_txt_too_large - Description for the image is longer than the limit of 1000 character
  • file_type_not_allowed - The file type is not allowed.
  • file_upload_size_restricted - The size of provided file is too large, as the team has restricted uploads of large files.
  • file_uploads_disabled - Team has disabled all file uploads.
  • file_uploads_except_images_disabled - File uploads except images are disabled.
  • missing_argument - A required argument was not provided. Typically only occurs when the length provided is 0.
  • snippet_too_large - The provided length is too large to create a snippet, which are limited to 1MB.
  • storage_limit_reached - File storage limit has been reached. This occurs when free teams have uploaded 5GB of files.
  • unknown_snippet_type - The provided snippet_type is not a supported type.
  • unknown_subtype - The provided subtype is not a supported type.

See the Common Errors guide for errors returned by every Web API method.

info(file, optional_params \\ %{})

Gets information about a file.

API reference

Rate limit: Tier 4: 100+ per minute
Scopes:

View on docs.slack.dev ↗

Required Params

  • file - Specify a file by providing its ID. ex: F2147483862

Optional Params

  • count -
  • cursor - Parameter for pagination. File comments are paginated for a single file. Set cursor equal to the next_cursor attribute returned by the previous request's response_metadata. This parameter is optional, but pagination is mandatory: the default value simply fetches the first "page" of the collection of comments. See pagination for more details. ex: dXNlcjpVMDYxTkZUVDI=
  • limit - The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the list hasn't been reached. 0 ex: 20
  • page -

Errors the API can return:

  • canvas_disabled_file_team - Canvas is disabled on file's team
  • canvas_disabled_user_team - Canvas is disabled on user's team for connected Channels
  • canvas_globally_disabled - Canvas is disabled for this team
  • file_deleted - The requested file has been deleted
  • file_not_found - Value passed for file was invalid
  • not_visible - Do not have permission to view the file
  • slack_connect_canvas_sharing_blocked - Admin has disabled sharing of Canvas links in all Slack Connect communications
  • template_not_visible - Do not have permissions to view this template

See the Common Errors guide for errors returned by every Web API method.

list(optional_params \\ %{})

List files for a team, in a channel, or from a user with applied filters.

API reference

Rate limit: Tier 3: 50+ per minute
Scopes:

View on docs.slack.dev ↗

Optional Params

  • channel - Filter files appearing in a specific channel, indicated by its ID.
  • count -
  • page -
  • show_files_hidden_by_limit - Show truncated file info for files hidden due to being too old, and the team who owns the file being over the file limit. ex: true
  • team_id - encoded team id to list files in, required if org token is used
  • ts_from - Filter files created after this timestamp (inclusive). ex: 123456789
  • ts_to - Filter files created before this timestamp (inclusive). ex: 123456789
  • types - Filter files by type (see below). You can pass multiple values in the types argument, like types=spaces,snippets.The default value is all, which does not filter the list. ex: images
  • user - Filter files created by a single user.

Errors the API can return:

  • missing_argument - A required argument is missing.
  • slack_connect_canvas_sharing_blocked - Admin has disabled sharing of Canvas links in all Slack Connect communications
  • unknown_type - Value passed for types was invalid
  • user_not_found - Value passed for user was invalid

See the Common Errors guide for errors returned by every Web API method.

revoke_public_url(file, optional_params \\ %{})

Revokes public/external sharing access for a file

API reference

Rate limit: Tier 3: 50+ per minute
Scopes:

View on docs.slack.dev ↗

Required Params

  • file - File to revoke

Errors the API can return:

  • file_not_found - Value passed for file was invalid

See the Common Errors guide for errors returned by every Web API method.

shared_public_url(file, optional_params \\ %{})

Enables a file for public/external sharing.

API reference

Rate limit: Tier 3: 50+ per minute
Scopes:

View on docs.slack.dev ↗

Required Params

  • file - File to share

Errors the API can return:

  • file_not_found - Value passed for file was invalid
  • not_allowed - Public sharing has been disabled for this team. You may see this error if you are creating an external link from a free or trial workspace. You can either upgrade to a Paid Plan or use file.list to get a url_private_download link, download the file with an application, and re-upload it somewhere it can be shared with users who are not members of your workspace. Be sure to pass the Slack Bot token to the request on the headers file when calling url_private_download.
  • public_file_type_not_allowed - Public sharing has been restricted for this file type.
  • public_video_not_allowed - Public sharing of videos is not available. A Free instance of Slack may encounter this error because free teams don't have the ability to share video files publicly.

See the Common Errors guide for errors returned by every Web API method.

upload(optional_params \\ %{})

Uploads or creates a file.

API reference

Rate limit: Tier 2: 20+ per minute
Scopes:

View on docs.slack.dev ↗

Optional Params

  • channels - Comma-separated list of channel names or IDs where the file will be shared.
  • content - File contents via a POST variable. If omitting this parameter, you must provide a file. You must provide either a file or content parameter. The content of the file can either be posted using an enctype of multipart/form-data (with the file parameter named file), in the usual way that files are uploaded via the browser, or the content of the file can be sent as a POST var called content. ex: ...
  • file - File contents via multipart/form-data. If omitting this parameter, you must submit content. You must provide either a file or content parameter. The content of the file can either be posted using an enctype of multipart/form-data (with the file parameter named file), in the usual way that files are uploaded via the browser, or the content of the file can be sent as a POST var called content. Possible filetype values can be found in the file object definition. ex: ...
  • filename - Filename of file. If you only specify a filename, we remove the file extension and populate the file's title with the remaining value. ex: foo.txt
  • filetype - A file type identifier. Possible filetype values can be found in the file object definition. ex: php
  • initial_comment - The message text introducing the file in specified channels. ex: Best!
  • thread_ts - Provide another message's ts value to upload this file as a reply. Never use a reply's ts value; use its parent instead.
  • title - Title of file. If you only specify a filename, we remove the file extension and populate the file's title with the remaining value. ex: My File

Errors the API can return:

  • blocked_file_type - Admin has disabled uploading this type of file
  • channel_not_found - At least one of the values passed for channels was invalid.
  • invalid_channel - One or more channels supplied are invalid
  • invalid_thread_ts - Value passed to thread_ts was invalid
  • malware_detected - This file may contain a virus or other malware and can't be uploaded to Slack
  • not_in_channel - Authenticated user is not in the channel.
  • post_contents_too_large - File content is larger than 130kb.
  • posting_to_general_channel_denied - An admin has restricted posting to the #general channel.
  • slack_connect_blocked_file_type - File uploads with certain types are blocked in all Slack Connect communications
  • slack_connect_clip_sharing_blocked - Admin has disabled Clip sharing in Slack Connect channels
  • slack_connect_file_upload_sharing_blocked - Admin has disabled File uploads in all Slack Connect communications

See the Common Errors guide for errors returned by every Web API method.