使用OpenRasta将图像作为流或字节数组获取

Mar*_*son 3 rest openrasta

有人能够给我一个快速指针,告诉我如何获得一个返回字节数组的OpenRasta处理程序.要在ResourceSpace中公开,而不是JSON或XML对象.即我不希望它转码,我只是希望能够将媒体类型设置为"图像/ PNG"或类似.

使用ASP.Net MVC我可以通过返回使用FileContentResult来完成它

File(myByteArray, "image/PNG");
Run Code Online (Sandbox Code Playgroud)

我只需要知道OpenRasta的等价物.

谢谢

Ser*_*Seb 10

您可以只返回一个字节数组作为处理程序的一部分,但最终将作为application/octet-stream提供.

如果要返回文件,只需返回IFile的实现即可.

public class MyFileHandler {
  public IFile Get(int id) {
    var mybytes = new byte[];
    return new InMemoryFile(new MemoryStream(mybytes)) {
      ContentType = new MediaType("image/png");
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

您还可以设置FileName属性以返回特定文件名,该文件名将为您呈现Content-Disposition标头.