From a84afe1904531284a9ece8bfde1686a4b3582c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Hump=C3=A1l?= Date: Mon, 1 Mar 2021 23:26:21 +0100 Subject: [PATCH] Use multipart HTTP request --- HttpApiUploadPlugin/HttpApiUploadStorage.cs | 11 +++++------ HttpApiUploadPlugin/SettingsControl.designer.cs | 2 +- HttpApiUploadPlugin/SettingsControl.resx | 2 +- README.md | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/HttpApiUploadPlugin/HttpApiUploadStorage.cs b/HttpApiUploadPlugin/HttpApiUploadStorage.cs index d9bf0e7..5a92b6b 100644 --- a/HttpApiUploadPlugin/HttpApiUploadStorage.cs +++ b/HttpApiUploadPlugin/HttpApiUploadStorage.cs @@ -30,16 +30,15 @@ public override async Task SaveImage(byte[] data, string shot return new StorageSaveResult(SavingResultCode.RequiresOptionsSetup, "API URL has to be set"); } - var values = new Dictionary - { - {"dataurl", GetDataURL(data, shotName)} - }; - try { using (var client = new HttpClient()) { - var content = new FormUrlEncodedContent(values); + var content = new MultipartFormDataContent() + { + { new StringContent(GetDataURL(data, shotName)), "dataurl" } + }; + client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain")); diff --git a/HttpApiUploadPlugin/SettingsControl.designer.cs b/HttpApiUploadPlugin/SettingsControl.designer.cs index 13190b3..662a25f 100644 --- a/HttpApiUploadPlugin/SettingsControl.designer.cs +++ b/HttpApiUploadPlugin/SettingsControl.designer.cs @@ -125,7 +125,7 @@ private void InitializeComponent() this.helpTextLabel.Location = new System.Drawing.Point(10, 184); this.helpTextLabel.Margin = new System.Windows.Forms.Padding(10, 20, 3, 20); this.helpTextLabel.Name = "helpTextLabel"; - this.helpTextLabel.Size = new System.Drawing.Size(356, 150); + this.helpTextLabel.Size = new System.Drawing.Size(368, 150); this.helpTextLabel.TabIndex = 22; this.helpTextLabel.Text = resources.GetString("helpTextLabel.Text"); // diff --git a/HttpApiUploadPlugin/SettingsControl.resx b/HttpApiUploadPlugin/SettingsControl.resx index 3312268..743afd5 100644 --- a/HttpApiUploadPlugin/SettingsControl.resx +++ b/HttpApiUploadPlugin/SettingsControl.resx @@ -121,7 +121,7 @@ 17, 22 - This plugin sends HTTP POST request to the specified URL. + This plugin sends HTTP multipart POST request to the specified URL. The only field is "dataurl" with Base64 encoded image contents. Accept of the request is "text/plain". diff --git a/README.md b/README.md index 754e921..223f9f0 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Built on [example plugin](https://github.com/name1ess0ne/CloudShot.Plugins/tree/ ## API expectations -This plugin sends a simple form-data HTTP POST request to the URL specified in plugin settings. +This plugin sends a simple multipart HTTP POST request to the URL specified in plugin settings. The only field in the request is `dataurl` with Base64-encoded image contents. Accept header of the request is `text/plain`.