Написание PDF-контента в ответном потоке в openrasta - PullRequest
1 голос
/ 14 декабря 2011

Я хочу сделать PDF в Iframe.Поэтому, если я сделаю запрос GET для http://localhost/pdf/2,, он должен вернуть содержимое PDF в потоке ответов.Другим способом может быть перенаправление пользователя на полный URL-адрес файла PDF, что я не хочу делать.

Заранее спасибо

1 Ответ

0 голосов
/ 18 декабря 2011

вы можете использовать классы InMemoryFile и InMemoryDownloadableFile. Пример:

private class AttachmentFile : InMemoryDownloadableFile
    {
        public AttachmentFile(byte[] file, string filename, string contenttype)
        {
            OpenStream().Write(file, 0, file.Length);
            this.FileName = filename;
            this.ContentType = new MediaType(contenttype);
        }
    }

    private class InlineFile : InMemoryFile
    {
        public InlineFile(byte[] file, string filename, string contenttype)
        {
            OpenStream().Write(file, 0, file.Length);
            this.FileName = filename;
            this.ContentType = new MediaType(contenttype);
        }
    }

    [HttpOperation(HttpMethod.GET)]
    public object Get(string filename)
    {

            bool inline = false; //server attachments inline or as download 
            try
            {
                inline = Convert.ToBoolean(Params["INLINE"]);
            }
            catch { }

            string contenttype = set contentttype...
            byte[] attachment = read file....

            if (inline)
                return new InlineFile(attachment, filename, contenttype);
            else return new AttachmentFile(attachment, filename, contenttype);   
        }
        else return new OperationResult.Forbidden();
    }
...