Cypress-file-upload: [Bug] Binary fixture upload

Created on 14 May 2019  Â·  7Comments  Â·  Source: abramenal/cypress-file-upload

Not sure if that should be considered a bug in cypress-file-upload since there is also an ongoing discussion for cypress itself: https://github.com/cypress-io/cypress/issues/1558. Still, I think it makes sense to point out that there is a problem with binaries.

Current behavior:

I am trying to upload binary files constituting a shapefile.
I specify "binary" as enconding, both for fixture and upload payload.
I get InvalidCharacterError: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded error when doing the upload.

Desired behavior:

Upload works correctly with encoding specified as "binary".

Steps to reproduce: (app code and test code)

cy.fixture("Test.shp", "binary").then(data => {                                                                                                          
  cy.get('#upload').upload(
    { fileContent: data, fileName: "Test.shp", encoding: "binary", mimeType: "application/octet-stream" },
    { subjectType: 'input' }
  );                                                                                 
});

Workaround

Use "base64" as encoding (both for fixture loading and upload).

Versions

cypress 3.2.0
cypress-file-upload: 3.1.1
Linux Mint 18.2 Cinnamon 64-bit

bug documentation not our bug

Most helpful comment

@abramenal I found workaround:

  • set encoding to base64 in cy.fixture()
  • set encoding in cy file upload also to base64.
    Works fine then.

All 7 comments

Hi @kammerer

Thanks for submitting the issue!
That is a really nice piece of documentation. Will reference that in README for others.

In the meantime, we can blame Cypress, they are blaming Node.js 😃
Personally I'm not a fan of making something that changes Cypress' behavior, so would wait a bit at least for having the final word from them – especially since we have a workaround you mentioned.
If they say they it won't be fixed – we'll think on either making a well-described special recipe/guide for binaries, or tweaking the plugin internally so it'll support that out-of-the-box.

Thanks for sharing this workaround!
I'm having the same issue, and now with "base64" on both fixture and upload, I get this error:

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

The file I'm uploading is a PDF file

Do you have an idea what goes wrong in my case?

@MaaikeFox It seems my workaround does not work universally :( Have you perhaps tried the approach proposed in https://github.com/cypress-io/cypress/issues/1558#issuecomment-380360944? It did not work in my case but who knows, perhaps it will work for PDFs.

@MaaikeFox please let us know your results – if that works, likely I need to extend PDF processing logic to support alternative encoding somehow..

Generally I suggest trying to play with encoding – start with the ones mentioned in Cypress docs: https://docs.cypress.io/api/commands/fixture.html#Arguments as those are supported by default.
If that does not work, we can bring a new encoding right to our code in order to support PDFs with non-trivial one.

I am happy to help with that, but the only thing here is – only you have this specific PDF, so if you can pick the investigation part and say what is the proper encoding for your PDF, I may bring support, add example with this file, etc.

I also noticed an issue with cypress-file-upload.
When I upload *.zip it's ok, when 7z I get error - I am attempting upload this file to some page which works fine if I do it manually. When uploading by cypress I get error that it cannot be unarchived. Made a test to check it with file write - size is 1kb less.
Moreover optional encoding returns error so I had to enter it myself as (utf-8). I tried to change mime type to bas64 but got the same error as MaaikeFox. Binary failed too but do not remember the error :(

@Pieras2 thanks for the feedback!
Likely we should create a separate issue for 7z if it's buggy – need to figure out how exactly we want it to be decoded.

@abramenal I found workaround:

  • set encoding to base64 in cy.fixture()
  • set encoding in cy file upload also to base64.
    Works fine then.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

nathanielongyiitak picture nathanielongyiitak  Â·  4Comments

sanduteo95 picture sanduteo95  Â·  7Comments

thiagobrez picture thiagobrez  Â·  8Comments

yonigibbs picture yonigibbs  Â·  5Comments

philjones88 picture philjones88  Â·  4Comments