Current behavior:
I have uploaded a PDF file and the upload was successful. But when I am trying to view the uploaded PDF document, it remains blank. I have tried uploading the same PDF file manually, its working as expected without any issues.
Desired behavior:
As the document upload was successful and it is having some content, it should not be blank.
Steps to Reproduce:
const fileName = 'testdoc1.pdf';
cy.fixture(fileName).then(fileContent => {
thresholdpage.getDragAndDrop().attachFile(
{ fileContent, fileName, mimeType: 'application/pdf' },
{ subjectType: 'drag-n-drop', force: true },
);
});
I am using cypress-file-upload to upload PDF. After uploading , I click on view document button to validate whether it was loaded successfully or not.
Versions:
Cypress 5.3.0
Chrome Version 84.0.4147.135 (Official Build) (64-bit)
Windows 10 64bit
I might have a similar problem where uploading a PNG file via 'drag-n-drop' doesn't work (Looks like it's empty/doesn't have a size). Uploading the same file through an 'input' works on the other hand.
@abramenal - Can you please give us an update on this? Is this a bug or is there any workaround for this problem?
Due to this issue our work is on hold from past 10 days. Please give an update as early as possible. Thanks in advance.
We're staying with 3.5.3 for now which seems to work with Cypress 5.5.0 as well 馃憤
@ericyahhh
I tried with Cypress 3.5.0 and 5.5.0 , still facing the same issue.
@abramenal - Hi, I have raised this issue long back but still there is no response. I got stuck in the middle of automation due to this issue. I have to inform my team on the status. Please suggest a workaround to solve this issue.
Hi @hbuddaraju-CLGX, thanks for submitting the issue. I recall it was indeed introduced in v4, so should work with v3.5.3, as @ericyahhh mentioned (thanks btw 馃憤 ).
So at the moment I think this is the only thing I can suggest. Otherwise feel free to take a look what's missing in current implementation ;)
@abramenal, Thanks! will look into it.
Still an issue. Just uploaded a pdf and it's blank pages, the page count is correct, just but no content.
Thanks to https://github.com/abramenal/cypress-file-upload/issues/275 the solution was pretty simple. The encoding is probably not being set properly, adding encoding: "base64" solved the issue.
cy.getBySel('file-drop').attachFile({filePath:`files/${fileName}`, encoding: "base64"})
Cypress: 6.5,
Electron 87,
cypress-file-upload: 5.0.2
I had issue with 2 different mime types and resolved that way:
// workaround mp4 and pdf files: https://github.com/abramenal/cypress-file-upload/issues/136
if (fixturePath.indexOf('.mp4') > -1 ||
fixturePath.indexOf('.pdf') > -1) {
const fileName = path.basename(fixturePath);
cy.fixture(fixturePath, 'binary')
.then(Cypress.Blob.binaryStringToBlob)
.then(fileContent => {
cy.get(el.fileUpload).attachFile({
fileContent,
fileName: fileName,
mimeType: fixturePath.indexOf('.mp4') ? 'video/mp4' : 'application/pdf',
encoding: 'utf8'
})
})
This code can be improved but i think it can give you a direction to go!
Think this is an issue with cypress itself - #15038
Also here's a repo to test the some sample file uploads: cypress-file-upload-tests
cy.get('[data-cy="file-input-po"]').attachFile({ filePath: "file.pdf", encoding: "base64" });
Still an issue. Just uploaded a pdf and it's blank pages, the page count is correct, just but no content.
Thanks to #275 the solution was pretty simple. The encoding is probably not being set properly, adding
encoding: "base64"solved the issue.cy.getBySel('file-drop').attachFile({filePath:`files/${fileName}`, encoding: "base64"})Cypress: 6.5,
Electron 87,
cypress-file-upload: 5.0.2
Thanks. This is solved my problems
Most helpful comment
Still an issue. Just uploaded a pdf and it's blank pages, the page count is correct, just but no content.
Thanks to https://github.com/abramenal/cypress-file-upload/issues/275 the solution was pretty simple. The encoding is probably not being set properly, adding
encoding: "base64"solved the issue.Cypress: 6.5,
Electron 87,
cypress-file-upload: 5.0.2