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

Use cy.api() with blob file returning TypeError #102

Open
CarolinaSL opened this issue Jan 2, 2023 · 6 comments
Open

Use cy.api() with blob file returning TypeError #102

CarolinaSL opened this issue Jan 2, 2023 · 6 comments
Assignees
Labels

Comments

@CarolinaSL
Copy link

CarolinaSL commented Jan 2, 2023

Hello! I'm with problems when I try to send a blob file through formData. The error returned is the following:

image

Some points :

-The same error is obtained using requestMode.

Cypress version: 12.1.0
Cypress-api-plugin version: 2.9.0

image

Here is the piece of code:

 .then((binary) => Cypress.Blob.binaryStringToBlob(binary))
        .then((blob) => {
            var path = pathFileFixture;
            let formData = new FormData();
            formData.append('file', blob, fileName);
            cy.api({
                method: 'POST',
                url: Cypress.env('api_url').file_storage,
                body: formData
@filiphric
Copy link
Owner

will create support for this soon 👍 thanks for the report. one question - before .then() command, do you use cy.fixture() to load the file?

@filiphric filiphric self-assigned this Jan 15, 2023
@filiphric filiphric added the enhancement New feature or request label Jan 15, 2023
@CarolinaSL
Copy link
Author

Yes, I use cy.fixture() to load the file. I appreciate your effort, thanks!

@piotrtar
Copy link

piotrtar commented Jan 19, 2023

Does it matter if you import a file by
import fileName from '../../fixtures/fileName.json'; or cy.fixture()?

@filiphric
Copy link
Owner

it seems that the formData on its own is not the core of the problem. I have been able to work OK with the following test:

it('uploads a file', () => {

  cy.fixture('logo.png', 'binary').then(image => {
    const blob = Cypress.Blob.binaryStringToBlob(image, 'image/png');
    const formData = new FormData();
    formData.append('image', blob, 'logo.png');

    cy.api({
      method: 'POST',
      url: '/',
      body: formData,
      headers: {
        'content-type': 'multipart/form-data'
      },
    })
  })


});

it doesn’t do too much, but it does not throw the error. is it possible for you to provide an example of what the response for such API call is?

@samirf-stubben-edge
Copy link

I'm facing the same issue and it seems to be related to the API response processing. Not the request.

Here is the response from my API:

<title>413 Request Entity Too Large</title>

413 Request Entity Too Large


nginx

Captura de tela 2023-06-14 095934

Captura de tela 2023-06-14 095752

@SivAlka
Copy link

SivAlka commented Jun 24, 2023

Seeing the same issue. I am using a fixture and modifying some objects in the json before passing to the endpoint. The operation itself seems successful as I can see the desired values changed in my application but I get the above mentioned error at the end. There is no error when using cypress native method

cy.fixture('').then((data) => {
    data.key1 = some value;
    cy.putWithTokenAPI(urlPath, accessToken, data).then((response) => {
      expect(response.status).to.eq(200);
    });
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants