using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using SlackNet;
using SlackNet.WebApi;
using UploadFile.Services;
class Program
{
static async Task Main()
{
string slackToken = "xoxb-my-token";
string channelId = "C0-cnannelid";
string filePath = @"C:\Users\Пользователь\Desktop\test.txt";
string fileName = Path.GetFileName(filePath);
byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
var api = new SlackServiceBuilder()
.UseApiToken(slackToken)
.GetApiClient();
var getUploadResponse = await api.Files.GetUploadUrlExternal(fileName, fileBytes.Length);
string uploadUrl = getUploadResponse.UploadUrl;
string fileId = getUploadResponse.FileId;
using var httpClient = new HttpClient();
using var fileContent = new ByteArrayContent(fileBytes);
fileContent.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
var uploadResponse = await httpClient.PutAsync(uploadUrl, fileContent);
uploadResponse.EnsureSuccessStatusCode();
var uploadedFiles = await api.Files.CompleteUploadExternal(
new[] { new ExternalFileReference { Id = fileId, Title = fileName } },
channelId: channelId
);
if (uploadedFiles.Count == 0)
{
throw new Exception("Ошибка: файл не прикрепился к каналу.");
}
}
}
I added bot to channel and bot has these bot token scopes:
channels:read
chat:write
dnd:read
files:read
files:write
groups:read
im:read
incoming-webhook
mpim:read
pins:read
pins:write
remote_files:read
remote_files:share
remote_files:write
User token scopes:
[*]chat:write
[*]files:read
[*]files:write
Pins: Lesen Sie < /li>
Pins: Schreiben Sie < /li>
Remote_files: Lesen Sie < /li>
remote_files: share < /li>
< /ol>
Hier ist mein Code - bitte helfen Sie mir bei Arbeitsbeispielen, wie Sie die Datei in Slack laden. Mein Code funktioniert ohne Fehler[code]using System; using System.IO; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Text.Json; using System.Threading.Tasks; using SlackNet; using SlackNet.WebApi; using UploadFile.Services;
class Program { static async Task Main() { string slackToken = "xoxb-my-token"; string channelId = "C0-cnannelid"; string filePath = @"C:\Users\Пользователь\Desktop\test.txt";
using var httpClient = new HttpClient(); using var fileContent = new ByteArrayContent(fileBytes); fileContent.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
var uploadResponse = await httpClient.PutAsync(uploadUrl, fileContent); uploadResponse.EnsureSuccessStatusCode();
var uploadedFiles = await api.Files.CompleteUploadExternal( new[] { new ExternalFileReference { Id = fileId, Title = fileName } }, channelId: channelId );
if (uploadedFiles.Count == 0) { throw new Exception("Ошибка: файл не прикрепился к каналу."); } } } [/code] I added bot to channel and bot has these bot token scopes: [list] [*]channels:read [*]chat:write [*]dnd:read [*]files:read [*]files:write [*]groups:read [*]im:read [*]incoming-webhook [*]mpim:read [*]pins:read [*]pins:write [*]remote_files:read [*]remote_files:share [*]remote_files:write [/list] User token scopes:
[*]chat:write [*]files:read [*]files:write Pins: Lesen Sie < /li> Pins: Schreiben Sie < /li> Remote_files: Lesen Sie < /li> remote_files: share < /li> < /ol>
Da die Slack -Datei.Upload abgeschrieben wird, würde ich die Methoden neu machen.curl -s -F [email protected] -F filename=test.txt -F token=xoxp-token -F length=50123
Ich habe mein Python-Paket auf PyPI hochgeladen.
Aber jetzt habe ich eine neue Version meines Pakets erstellt und muss es hochladen.
Ich habe versucht, den gleichen Fortschritt zu erzielen wie beim...
Ich habe einen Datenfluss in einer FastAPI-Anwendung, bei dem ein möglicherweise sehr großer HTTP-PUT-Body hochgeladen wird, und ich muss diesen an Google Cloud Storage streamen. Ich verwende die...
Ich versuche, eine große Datei (≥3 GB) auf meinen FastAPI-Server hochzuladen, ohne die gesamte Datei in den Speicher zu laden, da mein Server nur über 2 GB freien Speicher verfügt. Serverseite :...