private async void UploadHttpClient(DualFormatService dualFormatService, string path, byte[] pictureData, string namePicture) { try { using (var client = new HttpClient()) { client.Timeout = TimeSpan.FromSeconds(60); using (var content = new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture))) { content.Add(new StreamContent(new MemoryStream(pictureData)), "fichier", namePicture); using (var message = await client.PostAsync("http://www.noelshack.com/api.php", content)) { var reponse = await message.Content.ReadAsStringAsync(); if (!reponse.Contains("http://www.noelshack.com")) { return; } dualFormatService.Uploaded(path, this.CustomUrl(reponse)); } } } } catch (Exception e) { this.logger.Error(e.Message); } }
// Upload second picture public void Upload(DualFormatService dualFormatService, string path, byte[] pictureData, string format) { var namePicture = new Random().Next(0, 9999).ToString("0000") + "-" + Properties.Resources.NamePicture + "." + format; this.UploadHttpClient(dualFormatService, path, pictureData, namePicture); }