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 ai = await _baseController.LoadFileGet(url, SetQueryStringAndSqlQueryParams); if (ai == null) { 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()); } if (ai.Stream == null) { return; } Response.BinaryWrite(ai.Stream); } catch (Exception ex) { WriteExceptionStatus(ex); } break; } }
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; } }