Something wrong with user image file

good day!
In the test, I have to pass the image and video to the request, for this I first convert it to an array of numbers and then pass it using “http. file”.
An error occurred while executing the request: IdentityHandler: something wrong with user image file

Could you know how to solve this error?

Hi @Sholpan,

Have you looked at this article on how to upload files? If that methods doesn’t work for you, please post some relevant code and possibly an example how an upload works with curl


I think you need the 'b' parameter when calling open, not http.file where the 2nd argument represents the filename. Without the 'b' parameter, the image variable will be a string representation of the binary data (likely UTF-8 but not 100% sure on that). It could be that subsequently converting this string representation into a FileData object that the data becomes corrupted.

I’ll mention that native JSON doesn’t support binary data, and so what typically happens is binary data are encoded using base64, which is very different from what you’d be uploading in this way. Do you know what the server is expecting (do you have a recording to compare against)?

I expect a response from server 200.
All my tests are saved in json format and I wrote one script for them. To pass the image and video in the tests, I first transform them into an array of numbers. Then I pass the resulting array of numbers to the test and run the script. And when I run it, I get an error that something is wrong with the image, I assume they are damaged.
Could you tell me how best to implement this?



import http from "k6/http";
let image = open("./3.jpg", "b");

export default function() {"your URL here", image);

work? This is all you need to post the body of a single file. If you are using forms to do it usually you need to use formdata as shown in the advance example.

If something doesn’t work please show us the code posting/uploading and creating the body as a whole instead of as parts.

Thank you, I finally figured it out and fixed the bug in my test.