Get an image as a stream or an array of bytes using OpenRasta

Can anyone give me a quick pointer on how I can get an OpenRasta handler that returns an array of bytes. To be exposed in ResourceSpace without its JSON or XML object. that is, I don’t want it to be transcoded, I just want to set the media type to “image / PNG” or similar.

Using ASP.Net MVC I can do this with FileContentResult by returning

File(myByteArray, "image/PNG");

I just need to know the equivalent of OpenRasta.

thank

+3
source share
3 answers

handlerm, 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");
    }
  }
}

FileName , Content-Disposition.

+10

OpenRasta, : http://groups.google.com/group/openrasta/browse_thread/thread/5ae2a6d653a7421e# http://groups.google.com/group/openrasta/browse_thread/thread/a631d3629b25b88a#

:

:

ResourceSpace.Has.ResourcesOfType<IFile>()
   .AtUri("/customer/{id}/avatar")
   .HandledBy<CustomerAvatarHandler>();

Handler:

public class CustomerAvatarHandler
{
    public object Get(int id)
    {
        const string filename = @"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Sunset.jpg";
        return new InMemoryFile(File.OpenRead(filename));
    }
}
+2

Stream, ,

ResourceSpace.Has.ResourcesOfType<byte[]>()
                .AtUri("/MyImageUri")
                .HandledBy<ImageHandler>();

, System.Drawing.Graphics, .

, , .

0

Source: https://habr.com/ru/post/1726446/


All Articles