简体   繁体   中英

Sending image data (base64) from client to server

This is my code for sending and image data over Errai Jax-RS:

    Model model = new Model();
    GWT.log("Before setting byte array");
    model.setImage(Base64.base64ToByteArray(base64)); 
    GWT.log("After setting byte array");
    modelService.call(new RemoteCallback<String>() {
        @Override
        public void callback(String hash) {
            GWT.log("Model upload with hash - " + hash);
        }
    }, new ErrorCallback() {
        @Override
        public boolean error(Message message, Throwable throwable) {
            showErrorModal();
            return false;
        }
    }).createModel(model);

The log shows that "After setting byte array" is logged before the client (browser) break, or hang. So the problem seems to be with the service call. Is it wrong to send base64 data like this? The test data send it about 350K bytes in size.

I would send the image in String instead of in a byte array.

So change the image attribute in your model to String, and convert from base64 string to byte array in server side when you need to handle the image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM