Код: Выделить всё
Updates required for apps still using the files.upload API
A workspace that you administer contains apps or integrations that recently used the files.upload web API method. We want to inform you about two important changes coming to support for the files.upload API.
May 8, 2024
Newly created Slack apps will no longer be able to access the files.upload API. Existing applications will be able to continue using files.upload until support is discontinued.
March 11, 2025
Support for the files.upload API for all apps will be discontinued.
To prepare for this change, we recommend that app owners migrate away from files.upload and instead use the combination of files.getUploadURLExternal(https://api.slack.com/methods/files.getUploadURLExternal) and files.completeUploadExternal(https://api.slack.com/methods/files.getUploadURLExternal). You can also leverage Slack's SDKs to help transition to this new way of uploading files by visiting our api.slack page(https://api.slack.com/messaging/files#uploading_files).
- Вызов files.getUploadURLExternal< /код>. Ответ будет содержать URL-адрес, по которому вы можете отправить содержимое вашего файла.
- Отправьте содержимое вашего файла по URL-адресу, возвращенному на шаге 1. Это можно сделать, отправив необработанный файл. байтах или может представлять собой завершенный запрос, состоящий из нескольких частей. Если все прошло хорошо, Slack ответит HTTP 200.
- Вызовите files.completeUploadExternal. При желании вы можете указать место назначения для общего доступа к вашему файлу или файлам, используя аргументы этого API. На этом загрузка файла, начатая на шаге 1, завершается.
Код: Выделить всё
// This method sends the test execution results report to Slack
public void sendTestExecutionReportToSlack() throws Exception {
String url = "https://slack.com/api/files.upload"; // This is the Slack url to upload the test execution results report to
try {
// This is the code to send the test execution report to Slack
HttpClient httpclient = HttpClientBuilder.create().disableContentCompression().build(); // Initiate the HttpClient to send the test execution results report to
HttpPost httppost = new HttpPost(url); // Post the Slack url
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); // Build the builder entity to host the test execution results report
FileBody fileBody = new FileBody(new File(PathToReport)); // Add the path of the test execution results report to the file body
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); // Set up the builder structure to send the test execution results report and make sure it is browser compatible
builder.addPart("file", fileBody); // Add the file containing the test execution results report to the builder structure
builder.addTextBody("channels", channelName); // Add the channelName to the builder TextBody
builder.addTextBody("token", botUserOAuthAccessToken); // Add the token to the builder TextBody
httppost.setEntity(builder.build()); // Set the Entity for builder, post the test execution results report with all the builder components including file, channels and token
HttpResponse response = null; // Set the HTTPResponse to null
response = httpclient.execute(httppost); // The response is equal to the result of httppost
HttpEntity result = response.getEntity(); // HTTPEntity Result equals the response of getEntity
} catch (Exception e) {
// If the code to send the test execution results report fails, print the associated stack trace
e.printStackTrace(); // Print the Stack Trace
}
}
Подробнее здесь: https://stackoverflow.com/questions/784 ... -slack-via
Мобильная версия