Upload images to gallery with REST API from widget.

Hi there!
I have a problem to make Post request to the photo gallery. I am trying to send the photos to 'api.ashx/v2/media/{contentID}/files.json ' and when I decode it to base64 I got a fully black image back.

But if I decode it to bytes[] I got the error: "Only a posted file, file URL, or file upload context is valid, but not more than one."

My full code in JavaScript ->

function setToGallery(content, name, description, image) {


  let fileConverter = fileReaderConverter(image)
     fileConverter.then((fileData)=>{

   $.telligent.evolution.post({
   url: $.telligent.evolution.site.getBaseUrl() + 'api.ashx/v2/media/' + content.galleryId + '/files.json',
      data: {
         MediaGalleryId: content.galleryId,
         Name: name,
         Description: description,
         FileName: image.name, // test.png
         ContentType: fileData.fileType, // "image/png"
         FileData: fileData.bytes, 
   },
   success: function (response) {
      console.log(response);
    }
   });

 })
}

   function fileReaderConverter(file){

     return new Promise((resolve, reject) => {

        const reader = new FileReader()
        reader.onloadend = () => {

        var bytes = new Uint8Array(reader.result.length / 2);

        for (var i = 0; i < reader.result.length; i += 2) {
          bytes[i / 2] = parseInt(reader.result.substring(i, i + 2), /* base = */ 16)
        }

          resolve({ 
               bytes: bytes,
               base64StringFile: reader.result,
               fileName: file.name, 
               fileType: file.type
          })}
       reader.onerror = reject
       reader.readAsDataURL(file)
})


 

  Some help will be very useful! Thanks!