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

9.3.0: selectFile: missing mimeType #19751

Closed
mduft opened this issue Jan 19, 2022 · 7 comments · Fixed by #19794
Closed

9.3.0: selectFile: missing mimeType #19751

mduft opened this issue Jan 19, 2022 · 7 comments · Fixed by #19794
Assignees
Labels
v9.3.0 🐛 Issue present since 9.3.0

Comments

@mduft
Copy link

mduft commented Jan 19, 2022

Current behavior

Switching from cypress-file-upload currently not possible. We're using attachFile to put a PNG file (test.png) in a hidden input[type="file"]. The application uses:

<input type="file" hidden (change)="onImageChange($event)" #fileInput />
/* template */ onImageChange(event) {
    if (event.target.files && event.target.files.length > 0) {
        const selLogoFile: File = event.target.files[0];
        console.log('XX: ' + selLogoFile.type);
    ....

The output when actually filling the file input (triggered using fileInput.click()) with a PNG file is XX: image/png. Using cypress-file-upload we specified this mimeType also in the test:

cy.get('input[type="file"]').attachFile({ filePath: 'test.png', mimeType: 'image/png' });

This also yielded the same console output (XX: image/png).

Now, reworking to selectFile, the code no longer supports mime type, and we need to explicitly force on invisible input:

cy.get('input[type="file"]').selectFile({ contents: 'cypress/fixtures/test.png' }, { force: true });

After this, the output is now only XX: - no mime type is present. According to the documentation manual setting of mime type should not be necessary due to improved binary handling (or so tails tell) xD

Desired behavior

Cypress should detect the mime type and encoding of files used from fixtures directory in selectFile as documented

Test code to reproduce

Unfortunately cypress-test-tiny does not provide a way to host a simple HTML page to test, and I cannot find any good example online of such an input field where the mime type of the file is shown somewhere ...

Cypress Version

9.3.0

Other

No response

@perglervitek
Copy link

I hope, that the binary will be fixed and also it will be possible to manually set the mimeType. Luckily cypress-file-upload still does the job.

@emilyrohrbough emilyrohrbough changed the title 9.0.0: selectFile: missing mimeType 9.3.0: selectFile: missing mimeType Jan 19, 2022
@BlueWinds
Copy link
Contributor

You're absolutely right, and this is an oversight on our part; I could give a long explanation of how it happened, but short version is 'whoops'.

Starting work on this today, prioritized this for the next minor release.

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: work in progress and removed stage: to do stage: needs review The PR code is done & tested, needs review labels Jan 19, 2022
@mduft
Copy link
Author

mduft commented Jan 20, 2022

:D we all 'whoops' from time to time :) Looking forward to the fix

@pauwilk
Copy link
Contributor

pauwilk commented Jan 20, 2022

Hey, just to be sure - I have a problem when my input has accept="image/png" - the command passes but nothing is uploaded. When I have accept=".png" in my input, everything is ok.
Do I understand correctly that the issue is related to the one described above?

@perglervitek
Copy link

Hey, just to be sure - I have a problem when my input has accept="image/png" - the command passes but nothing is uploaded. When I have accept=".png" in my input, everything is ok.

Yes, you either have accept parameter on check file.type in your app. That's the reason, why it's refusing the uploaded file.

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: work in progress labels Jan 20, 2022
@jennifer-shehane jennifer-shehane added the v9.3.0 🐛 Issue present since 9.3.0 label Jan 20, 2022
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Jan 21, 2022
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jan 21, 2022

The code for this is done in cypress-io/cypress#19794, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jan 31, 2022

Released in 9.4.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v9.4.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
v9.3.0 🐛 Issue present since 9.3.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants