public async Task ShowImpl(String Base, String id, HttpResponseBase Response, Action <ExpandoObject> setParams, String suffix, String token) { try { var url = $"/_attachment{Base}/{id}"; var ai = await _baseController.DownloadAttachment(url, setParams, suffix); if (ai == null) { throw new RequestModelException($"Attachment not found. (Id:{id})"); } if (!_baseController.IsTokenValid(Response, ai.Token, token)) { return; } Response.ContentType = ai.Mime; Response.BinaryWrite(ai.Stream); } catch (Exception ex) { _baseController.WriteHtmlException(ex, Response.Output); } }
async Task DoFile(String url) { switch (Request.HttpMethod.ToUpperInvariant()) { case "POST": if (IsNotAjax()) { return; } Response.ContentType = "application/json"; try { var files = Request.Files; await _baseController.SaveFiles(url, files, SetQueryStringAndSqlQueryParams, Response.Output); } catch (Exception ex) { WriteExceptionStatus(ex); } break; case "GET": try { var token = Request.QueryString["token"]; if (token == null) { throw new InvalidOperationException("There is no access token for image"); } var ai = await _baseController.LoadFileGet(url, SetQueryStringAndSqlQueryParams); if (ai == null) { throw new InvalidOperationException($"Not found. Url='{url}'"); } if (!_baseController.IsTokenValid(Response, ai.Token, token)) { return; } Response.ContentType = ai.Mime; if (Request.QueryString["export"] != null) { var cdh = new ContentDispositionHeaderValue("attachment") { FileNameStar = _baseController.Localize(ai.Name) }; Response.Headers.Add("Content-Disposition", cdh.ToString()); } else { CacheImage(ai); } if (ai.Stream != null) { Response.BinaryWrite(ai.Stream); } } catch (Exception ex) { var accept = Request.Headers["Accept"]; if (accept != null && accept.Trim().StartsWith("image", StringComparison.OrdinalIgnoreCase)) { WriteImageException(ex); } else { WriteExceptionStatus(ex); } } break; } }