S
S
Sinus_3142021-05-11 16:57:45
Java
Sinus_314, 2021-05-11 16:57:45

How to transfer image via netty?

I'll soon be ready to give my soul for knowing how to transfer an image or file through netty.
I tried to write my own handler - I get crutches that still don’t work, I tried to wrap it in an object and pass it in - so the server simply doesn’t receive anything, I also tried using SimpleChannelInboundHandler (), but the situation is the same.

Please don't let me die, pamagiti

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-05-11
@sergey-gornostaev

A rough sketch of the server-side handler:

public class FileServerHandler extends SimpleChannelInboundHandler<String> {
    @Override
    public void messageReceived(ChannelHandlerContext ctx, String fileName) throws Exception {
        RandomAccessFile file = new RandomAccessFile(fileName, "r");
        ctx.write(new DefaultFileRegion(file.getChannel(), 0, file.length()));
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question