예제 #1
0
        public HttpResponseMessage GetFile(int id, Platform platform)
        {
            var repo = new FileAccesRepository <AssetBundle>(new MySqlConnectionFactory(),
                                                             subFolder: platform.ToString());

            var result = new HttpResponseMessage(HttpStatusCode.NotFound);

            if (Enum.IsDefined(typeof(Platform), platform) == false)
            {
                return(result);
            }

            var(data, name) = repo.GetFile(id);

            if (data != null)
            {
                result.Content = new ByteArrayContent(data.ToArray());
                result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = name
                };
                result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

                result.StatusCode = HttpStatusCode.OK;
            }

            return(result);
        }
예제 #2
0
        public HttpResponseMessage GetFile(int id, bool isXml = false)
        {
            var repo   = new FileAccesRepository <DataSet>(new MySqlConnectionFactory(), extension: isXml ? "xml" : "dat");
            var result = new HttpResponseMessage(HttpStatusCode.InternalServerError);

            var(data, name) = repo.GetFile(id);

            if (data != null)
            {
                result.Content = new ByteArrayContent(data.ToArray());
                result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = name
                };
                result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

                result.StatusCode = HttpStatusCode.OK;
            }
            else
            {
                result.StatusCode = HttpStatusCode.NotFound;
            }

            return(result);
        }