简体   繁体   中英

Trouble converting jpeg image to the correct byte array

I was trying to send some data through a SOAP service call. Currently I am having issue to send the correct image data format(or maybe some other issues I am not aware).

I am using laptop webcam to take a photo and pass the jpeg data to my back-end through ajax call and successful. The JavaScript library I am using is from here:

https://github.com/jhuckaby/webcamjs

After taking the photo, I am sending the picture to the back end so in the $.ajax i did this:

data : JSON.stringify({imageData : data})

On my java side, I grabbed the imageData by converting it from String to byte[] :

String imageData = jsonObj.getString("imageData");
byte[] finalImage = imageData.getBytes();

The problem I am having right now is if I send this finalImage byte array to the SOAP service call, I got an error respond saying the file is either missing or too large(over 1mb). I did a finalImage.length and it returns 7120. So I think the file is definitely not over 1mb in terms of size.

I created a test.jpeg file from my Windows OS using Snipping Tool and did the following and the SOAP service happily accepted, the length of the testImage byte array is 7884 is:

File fi = new File("test.jpeg");
byte[] testImage= Files.readAllBytes(fi.toPath());

What could be the reason? The file not in the correct format?

我认为图像文件的重量可能不会达到7kb ...这里有些问题...也许检查文件是否有问题或类似问题。

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