abramenal / cypress-file-upload

File upload testing made easy
https://npm.im/cypress-file-upload
MIT License
496 stars 89 forks source link

[Bug] Need to specify encoding: "base64" for `.png` and `.jpg` images on cypress-file-upload version 5.0.2 #275

Closed inovramadani closed 2 years ago

inovramadani commented 3 years ago

Current behavior:

Need to explicitly add encoding property to upload image properly. Below is part of my test code:

export const sendImageMessage = (fileName, mimeType) => {
  cy.fixture(`pictures/${fileName}`)
    .then(fileContent => {
      cy.get('input#image-upload[type=file]')
        .attachFile(
          { fileContent, fileName, mimeType, encoding: 'base64' }, // need to explicitly add encoding property here to upload image properly
          { subjectType: 'input' }
        )
    })
}

Without adding encoding, the image is broken. The file input change handler will upload the image into s3 in my app functionality. If I try to download from s3 url from the upload callback, it will be showing as It looks like we don't support this file format. And the s3 url will be shown instead of the image on my app.

Desired behavior:

Should be able to upload image smoothly without explicitly add encoding property. It worked fine when I used cypress-file-upload version 3.2.0. But after upgrading to 5.0.2 I need to do the above workaround.

abramenal commented 2 years ago

Not an issue, since png/jpg/jpeg/gif/etc file extensions are being resolved into base64 file encodings. If your filename does not have extension (or have a different one), you have to specify encoding explicitly.