Closed manuel-neto-maitha closed 2 years ago
Hi, thanks for submitting the issue!
Can you please try setting the encoding explicitly? I am not sure which one will work here, but you can probably try it out and let me know which one works. Later I can update implementation to support this out of the box.
cy.get('input[type="file"]').attachFile({ filePath: 'My.xml', encoding: 'base64' })
If base64
does not work, here is the list of supported encodings: https://github.com/abramenal/cypress-file-upload/blob/v5.0.8/lib/file/constants.js#L1. Note that you should use object value, not the key.
Looking forward your feedback!
Helo @abramenal thanks for the feedback.
I tried what you suggested but it didn't work. It seems to me that the problem is not in the encoding. The web application endpoint converts the file to a base64 string after uploading correctly. The dot is the snippet "data:application/xml;base64," which should not be present in the string.
It can also be that mimeType
that is internally determined by the plugin somehow affects processing logic. Maybe you can try something with that?
eg
cy.get('input[type="file"]').attachFile({ filePath: 'My.xml', mimeType: 'application/xml' })
Or on the contrary, set it to text/plain
so the converter should output it as is
@abramenal with mimeType: 'text/plain' works good, was solved.
The request stay with snipet 'data:text/plain;base64' in the init, but with text/plain, the POST method, returns 200.
Thank you for responses
Since this is specific to your setup, there is nothing I can do on plugin side. However feel free to reopen if you think there is something wrong.
Current behavior:
In my application, when uploading an XML file, manually, the request payload is formed correctly, and the upload is successful. The payload is similar with the json bellow, the application get the XML file and convert the file to one base64 string, and the string is invited in the payload.
However, when the upload is doing by the automated test with cypress-file-upload, the request payload is malformed, and the upload fails, because the string 'data:application/xml;base64' is added in the request, glued with the file content in base64 string.
Desired behavior:
I need the payload to be formed correctly, without 'data:application/xml;base64' in the init of the string.
Steps to reproduce: (app code and test code)
Versions
Ubuntu 20.04 Chrome 95 Cypress 7.2.0