question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

9.3.0: selectFile: missing mimeType

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
perglervitekcommented, 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.

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

2reactions
BlueWindscommented, Jan 19, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

selectFile - Cypress Documentation
Support for TypedArray and mimeType property added. Default fileName name is no longer lost when working with aliases. Community Recognition. The .selectFile() ...
Read more >
How to test file inputs with Cypress? - Stack Overflow
toString(), fileName: 'testPicture.png', mimeType: 'image/png' }); }); });. Use cypress file upload ... Since 9.3.0 you can use selectFile .
Read more >
How Do I Resolve the "HTTP MIME Types file is missing" Error ...
Symptoms. The filer is not shipped with the httpd. mimetypes file. Instead, the filer''s system files include a sample file named httpd.
Read more >
cypress 9.4.0 on Node.js NPM - NewReleases.io
selectFile () after receiving feedback after its initial release in 9.3.0. The default behavior was updated to automatically infer the mime type of...
Read more >
league/mime-type-detection - Packagist
$detector = new League\MimeTypeDetection\FinfoMimeTypeDetector(); // Detect by contents, fall back to detection by extension.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found