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] Binary fixture upload #70

Closed
kammerer opened this issue May 14, 2019 · 7 comments
Closed

[Bug] Binary fixture upload #70

kammerer opened this issue May 14, 2019 · 7 comments
Assignees
Labels
bug Something isn't working documentation not our bug

Comments

@kammerer
Copy link

Not sure if that should be considered a bug in cypress-file-upload since there is also an ongoing discussion for cypress itself: cypress-io/cypress#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

@kammerer kammerer added the bug Something isn't working label May 14, 2019
@abramenal
Copy link
Owner

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.

@MaaikeFox
Copy link

MaaikeFox commented May 23, 2019

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?

@kammerer
Copy link
Author

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

@abramenal
Copy link
Owner

@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.

@Pieras2
Copy link

Pieras2 commented Aug 19, 2019

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 :(

@abramenal
Copy link
Owner

@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.

@Pieras2
Copy link

Pieras2 commented Aug 20, 2019

@abramenal I found workaround:

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

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

No branches or pull requests

4 participants