Skip to content

Commit

Permalink
add ability to send text with the image
Browse files Browse the repository at this point in the history
  • Loading branch information
met-nikita committed Apr 4, 2022
1 parent f1ffa4d commit c165051
Show file tree
Hide file tree
Showing 7 changed files with 1,051 additions and 265 deletions.
3 changes: 3 additions & 0 deletions DSAS/DSAS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
<EmbeddedResource Include="Form1.ru-RU.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Form1.ru.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
Expand Down
24 changes: 20 additions & 4 deletions DSAS/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions DSAS/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public partial class MainWindow : Form
string lastFolder = "";
string lastUrl = "";
string filter = "*.jpg";
string msgText = "";
public MainWindow()
{
if(config.AppSettings.Settings["lastFolder"] != null)
Expand All @@ -31,10 +32,13 @@ public MainWindow()
lastUrl = ConfigurationManager.AppSettings["lastUrl"];
if (config.AppSettings.Settings["filter"] != null)
filter = ConfigurationManager.AppSettings["filter"];
if (config.AppSettings.Settings["msgText"] != null)
msgText = ConfigurationManager.AppSettings["msgText"];
InitializeComponent();
tb_scrfolder.Text = lastFolder;
tb_webhookurl.Text = lastUrl;
tb_filter.Text = filter;
tb_msgtext.Text = msgText;
}

private void b_browse_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -108,8 +112,9 @@ async private void SendFile(string file)
SendFile(file);
return;
}
MultipartFormDataContent form = new MultipartFormDataContent();
form.Add(new ByteArrayContent(file_bytes, 0, file_bytes.Length), "file", Path.GetFileName(file));
MultipartFormDataContent form = new MultipartFormDataContent();
form.Add(new StringContent("{\"content\": \""+tb_msgtext.Text+"\",\"attachments\": [{\"id\": 0,\"description\": \"screenshot\",\"filename\": \"scr.jpg\"}]}"), "payload_json");
form.Add(new ByteArrayContent(file_bytes, 0, file_bytes.Length), "files[0]", Path.GetFileName(file));
try
{
await httpClient.PostAsync(tb_webhookurl.Text, form);
Expand Down Expand Up @@ -187,6 +192,8 @@ private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
config.AppSettings.Settings.Add("lastUrl", tb_webhookurl.Text);
config.AppSettings.Settings.Remove("filter");
config.AppSettings.Settings.Add("filter", tb_filter.Text);
config.AppSettings.Settings.Remove("msgText");
config.AppSettings.Settings.Add("msgText", tb_msgtext.Text);
config.Save(ConfigurationSaveMode.Modified);
}

Expand Down Expand Up @@ -234,7 +241,8 @@ private void b_test_Click(object sender, EventArgs e)
}
byte[] file_bytes = ImageToByteArray(testpic.testpic1);
MultipartFormDataContent form = new MultipartFormDataContent();
form.Add(new ByteArrayContent(file_bytes, 0, file_bytes.Length), "file", "scr.jpg");
form.Add(new StringContent("{\"content\": \"Hello, World!\",\"attachments\": [{\"id\": 0,\"description\": \"screenshot\",\"filename\": \"scr.jpg\"}]}"), "payload_json");
form.Add(new ByteArrayContent(file_bytes, 0, file_bytes.Length), "files[0]", "scr.jpg");
try
{
httpClient.PostAsync(tb_webhookurl.Text, form);
Expand Down
Loading

0 comments on commit c165051

Please sign in to comment.