Метод API files.upload устарел для загрузки результатов тестов в Slack через Selenium WebDriver 4.0JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Метод API files.upload устарел для загрузки результатов тестов в Slack через Selenium WebDriver 4.0

Сообщение Anonymous »

Я использую Selenium WebDriver 4.19 с Java и загружаю результаты своих тестов в Slack. На днях Slack уведомил меня о том, что метод веб-API files.upload, который я использую для этого, устарел.

Код: Выделить всё

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).
Согласно странице api.slack, это инструкции по решению проблемы.
  • Вызов files.getUploadURLExternal< /код>. Ответ будет содержать URL-адрес, по которому вы можете отправить содержимое вашего файла.
  • Отправьте содержимое вашего файла по URL-адресу, возвращенному на шаге 1. Это можно сделать, отправив необработанный файл. байтах или может представлять собой завершенный запрос, состоящий из нескольких частей. Если все прошло хорошо, Slack ответит HTTP 200.
  • Вызовите files.completeUploadExternal. При желании вы можете указать место назначения для общего доступа к вашему файлу или файлам, используя аргументы этого API. На этом загрузка файла, начатая на шаге 1, завершается.
Вот существующий код, который я использую с files.upload. Код заботится об отправке содержимого на Java. Я новичок/очень знаком с Java. Я не понимаю, что они имеют в виду под вызовами files.getUploadURLExternal и вызовами files.completeUploadExternal. Есть ли у кого-нибудь пример кода Java, объясняющий, как работают эти операторы вызова.

Код: Выделить всё

// 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://api.slack.com/methods/files.get ... RLExternal требует обязательного аргумента целого числа/длины (размер загружаемого файла в байтах). Можно ли это сделать с помощью builder.addPart()

Подробнее здесь: https://stackoverflow.com/questions/784 ... -slack-via
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»