Cypress Blob gives error Failed to execute 'atob' on 'Window', with mkv file

Viewed 90

I need to test API, with a MKV file in the request.

I use the following code for that:

        cy.fixture('video.mkv').then(file => {
            const blob = Cypress.Blob.base64StringToBlob(file, "video/x-matroska")
            cy.request({
                method: ...
                url: ...
                body: blob,
            })

        });

Finally, I have this error:

"InvalidCharacterError Failed to execute 'atob' on 'Window': The string to be decoded contains characters outside of the Latin1 range."

I'm not sure that, for MKV file, I should convert base64 strings to Blob objects.

FYI: I test with Cypress v10.0.0 Can you help me, please?

2 Answers

I think you are looking for arrayBufferToBlob

cy.fixture('video.mkv').then(file => {
  const blob = Cypress.Blob.arrayBufferToBlob(file, "video/x-matroska")
  cy.request({...
})

These are the available Blob functions, and arrayBufferToBlob looks likely (at least, no errors).

Try out other methods if no-go on this one.

In fact, with a MKV file, it appears that I don't need to convert to blob object, as the request is well sent with this file:

    cy.fixture('video.mkv').then(file => {
        cy.request({
            method: ...
            url: ...
            body: **file**,
        })

    });

However, the video is always damaged after the request. Here are file content for comparison, before and after:

Original content: enter image description here

Output content: enter image description here

We can see that a part was modified, like 'A3' at the beginning, replaced by 'EF BF BD'

Note that this service works fine, ouside Cypress, and we are able to retrieve output video.

Related