//public async Task<string> DownloadMap(DownloadMapModel model) public string DownloadMap(DownloadMapModel model) { var fileName = $"announcementMap{model.AnnouncementId}.jpg"; var dest = fileName.GetDestFileName(); dest = FilesUtilities.GetRelativePath(dest, UploadType.AnnouncementPhoto, model.AnnouncementId); var newFile = Path.Combine(_webRootPath, dest); newFile = newFile.SlashConverter(); Path.GetDirectoryName(newFile).CreateDirectory(); var webRequest = WebRequest.Create(model.Url); webRequest.Method = "GET"; webRequest.ContentType = "image/png"; var webResponse = webRequest.GetResponse(); var stream = webResponse.GetResponseStream(); using (var fileStream = new FileStream(newFile, FileMode.Create, FileAccess.Write)) { stream?.CopyTo(fileStream); } //await Callback(Path.GetFileName(newFile), model.AnnouncementId, AttachmentType.OtherImages); return(!model.IsRelativeRequested ? Path.GetFileName(dest) : dest); }
public async Task <string> DownloadMap(DownloadMapModel model) { var serializedModel = Utilities.SerializeObject(model); var content = new StringContent(serializedModel, Encoding.UTF8, "application/json"); using (var client = new HttpClient()) { var response = await client.PostAsync($"{ConstValues.MediaBaseUrl}{ConstValues.DownloadMap}", content); if (response.StatusCode != HttpStatusCode.OK) { return(null); } var serialized = await response.Content.ReadAsStringAsync(); var deserialized = JsonConvert.DeserializeObject <ServiceResult>(serialized); return(!deserialized.Success ? null : deserialized.Data.ToString()); } }
public IActionResult DownloadMap([FromBody] DownloadMapModel model) { return(MakeActionCallWithModel(() => _service.DownloadMap(model), model)); }