我想在Iframe中呈现pdf。因此,如果我向http://localhost/pdf/2发出GET请求,它应该在响应流中返回PDF内容。另一种方法是将用户重定向到我不想做的PDF文件的完整URL。
提前致谢
答案 0 :(得分:0)
您可以使用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();
}