Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] - Trying to upload a video/mp4 with binary encoding fails #136

Closed
teophilus opened this issue Dec 11, 2019 · 14 comments
Closed

[Bug] - Trying to upload a video/mp4 with binary encoding fails #136

teophilus opened this issue Dec 11, 2019 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@teophilus
Copy link

teophilus commented Dec 11, 2019

Current behavior:

image

image

$ file -I test_asset_02.mp4

test_asset_02.mp4: video/mp4; charset=binary

Desired behavior:

Trying to upload a video/mp4 with binary encoding fails, I used the same command for Jpegs and such and they work perfect.

Steps to reproduce: (app code and test code)

Upload an video/mp4 with binary encoding

Versions

Cypress: 3.5.0 , operating system: locally OSX but running against a production server (Unix), browser: Electron

@teophilus teophilus added the bug Something isn't working label Dec 11, 2019
@abramenal
Copy link
Owner

Hi @teophilus

Thanks for submitting the issue!
Can you please provide the code snippet? It seems it should work, as binary is one of the supported encodings:
https://github.com/abramenal/cypress-file-upload/blob/master/src/constants.js#L29

@jackguoAtJogg
Copy link

I have same issue, here's my code snippet:

.fixture('sample_video.mp4')
            .then(fileContent => {
                cy.get('#upload-video').upload({
                    fileContent,
                    fileName: 'sample_video.mp4',
                    mimeType: 'video/mp4',
                    encoding: 'binary'
                })
            })

@jackguoAtJogg
Copy link

But I'm getting different error.
image

@jackguoAtJogg
Copy link

I got it fixed by setting encoding to 'utf8'.

.fixture('bear.mp4')
            .then(fileContent => {
                cy.get('#upload-video').upload({
                    fileContent,
                    fileName: 'bear.mp4',
                    mimeType: 'video/mp4',
                    encoding: 'utf8'
                })
            })

@abramenal
Copy link
Owner

@jackguoAtJogg
Thanks for this!

@all-contributors add @jackguoAtJogg for question

@allcontributors
Copy link
Contributor

@abramenal

I've put up a pull request to add @jackguoAtJogg! 🎉

@abramenal
Copy link
Owner

Mentioned the workaround in 97e2f46

@jackguoAtJogg
Copy link

Wow~ is my honor to be part the contributor~ 😁

@inovramadani
Copy link

Hello, in my case where I used mp4box library to have a check on video metadata before sending a video, the above workaround does not work. It produces wrong video metadata. The below workaround works:

  • set encoding to base64 in cy.fixture()
  • set encoding in cypress-file-upload .attachFile to base64.

@jackguoAtJogg
Copy link

jackguoAtJogg commented May 21, 2021

I got it fixed by setting encoding to 'utf8'.

.fixture('bear.mp4')
            .then(fileContent => {
                cy.get('#upload-video').upload({
                    fileContent,
                    fileName: 'bear.mp4',
                    mimeType: 'video/mp4',
                    encoding: 'utf8'
                })
            })

The upload not longer work with Cypress 7.3.0 and cypress-file-upload 5.0.7, all you need to do is to change from upload to attachFile.

@HindyB
Copy link

HindyB commented May 28, 2021

Hello, in my case where I used mp4box library to have a check on video metadata before sending a video, the above workaround does not work. It produces wrong video metadata. The below workaround works:

  • set encoding to base64 in cy.fixture()
  • set encoding in cypress-file-upload .attachFile to base64.

Hello,
Thank you for this, however, I'm trying to upload large or small video files then accepted, in order to test the right error message. The following result is obtained:
image

@pmerwin
Copy link

pmerwin commented Jun 9, 2021

Hello, in my case where I used mp4box library to have a check on video metadata before sending a video, the above workaround does not work. It produces wrong video metadata. The below workaround works:

  • set encoding to base64 in cy.fixture()
  • set encoding in cypress-file-upload .attachFile to base64.

for others this is what worked for me:

cy.fixture('vidtest.mp4', { encoding: 'base64' }).then((fileContent) => {
            cy.get('[data-testid="video-component-upload-dropzone-input"]').attachFile({
                fileContent,
                fileName: 'vidtest.mp4',
                mimeType: 'video/mp4',
                encoding: 'base64'
            });
        }); ```

@HindyB
Copy link

HindyB commented Jun 14, 2021

Hello, in my case where I used mp4box library to have a check on video metadata before sending a video, the above workaround does not work. It produces wrong video metadata. The below workaround works:

  • set encoding to base64 in cy.fixture()
  • set encoding in cypress-file-upload .attachFile to base64.

for others this is what worked for me:

cy.fixture('vidtest.mp4', { encoding: 'base64' }).then((fileContent) => {
            cy.get('[data-testid="video-component-upload-dropzone-input"]').attachFile({
                fileContent,
                fileName: 'vidtest.mp4',
                mimeType: 'video/mp4',
                encoding: 'base64'
            });
        }); ```

This works great for me, excluding uploading large video files

@Parth909
Copy link

{ encoding: 'base64' }

What do you mean by large. Approximately how much large

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants