简体   繁体   English

我如何将图像数据传递给控制者并转换为字节

[英]how can i pass a image data to controiller and convert into bytes

i am doing some in javascript like follows in front end 我在用javascript做一些像前端

if (this.files && this.files[0]) {
            var reader = new FileReader();
            reader.onload = function(e) {
                $('#brandImage').attr('src', e.target.result);
            },
            reader.readAsDataURL(this.files[0]);
        }

now whatever is there in brandImage is now looks to me some binary data of the image which is like src="data:image/jpeg;base64..and than some random characters.. 现在,brandImage中的内容现在对我来说是图像的二进制数据,例如src =“ data:image / jpeg; base64 ..,而不是一些随机字符。

now i want to transfer that data to the controller and in the controller i want to convert that binary data in bytes. 现在我想将该数据传输到控制器,并在控制器中我想将该二进制数据转换为字节。

is this possible 这可能吗

this data is binary data already, so you can pass everything you get to controller, but it is encoded with base64, so you need to decode it 此数据已经是二进制数据,因此您可以将获得的所有信息传递给控制器​​,但是它已使用base64进行编码,因此需要对其进行解码

for java use http://docs.oracle.com/cd/E12839_01/apirefs.1111/e12063/oracle/dss/util/BASE64Decoder.html 对于Java使用http://docs.oracle.com/cd/E12839_01/apirefs.1111/e12063/oracle/dss/util/BASE64Decoder.html

just don't forget to remove prefix data:image/jpeg;base64 from this data 只是不要忘记从此数据中删除前缀data:image/jpeg;base64

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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