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

Cannot send binary payload #23

Closed
YYOANN opened this issue Feb 11, 2020 · 3 comments
Closed

Cannot send binary payload #23

YYOANN opened this issue Feb 11, 2020 · 3 comments

Comments

@YYOANN
Copy link

YYOANN commented Feb 11, 2020

It seams impossible to send binary payload.
I have directly checked following example:

  - name: post binary data (file) as body
    request:
      path: /echoBinaryBodyResponseStats
      method: post
      headers:
        - name: content-type
          value: image/png
      payload:
          body:
            type: binary
            content: static/assets/logo.png
    response:
      status_code: 200
      json_data:
        - path: $.request_content_size
          value: 12371

And it sends [object Object] as body payload.
Further inspection show that it's a fs.ReadStream object (created in spec.js:515?).
Did I missconfigured something or is it a bug or not fully implemented feature?

Tested with node13 and just-api@1.2.5.

@YYOANN
Copy link
Author

YYOANN commented Feb 12, 2020

Patching the spec.js file with a synchronous read fixed the problem.
I'm not sure this is is what was intended.

-bodyData.body = fs.createReadStream(file);
+bodyData.body = fs.readFileSync(file);

Edit: removed encoding

@kiranz
Copy link
Owner

kiranz commented Feb 14, 2020

@YYOANN Just ran a test with node v13.8.0 and just-api v1.2.5 and it runs as expected.

Here's a sample suite I tried with.

meta:
  name: POST raw body requests (json , text, binary )
configuration:
  scheme: http
  host: 127.0.0.1
  port: 3027
specs:
  - name: post binary data (file) as body
    request:
      path: /echoBinaryBodyResponseStats
      method: post
      headers:
        - name: content-type
          value: image/png
      payload:
          body:
            type: binary
            content: static/assets/logo.png
    response:
      status_code: 200
      json_data:
        - path: $.request_content_size
          value: 12371

If you are still having issues, please update the issue with an attachment containing your suite so I can take look.

Note: Make sure that the file exists at static/assets/logo.png in the directory where you invoke tests from

@YYOANN
Copy link
Author

YYOANN commented Feb 17, 2020

I tried to reproduce the issue today and now everything is working as expected, locally and in docker, I can't figure out what was wrong. I'll update the issue if I find something.
Thanks for your help.

@YYOANN YYOANN closed this as completed Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants