简体   繁体   中英

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

i am doing some in javascript like follows in front end

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..

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

for java use 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

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