Giter Club home page Giter Club logo

Comments (7)

luza avatar luza commented on May 28, 2024

Currently there is no native way to pass a file, so to achieve that you have to construct the request body by yourself.

According to HTTP standard, you should use multipart/form-data mime type, define a separator and split body in two parts: one for POST parameters, second for the file content.

from gonkey.

devig avatar devig commented on May 28, 2024

Can you show small example?

from gonkey.

luza avatar luza commented on May 28, 2024

I wrote a tiny endpoint in PHP, which dumps request payload:

<?php

header('Content-Type: application/json');
die(json_encode(['post' => $_POST, 'files' => $_FILES]));

Here is a Gonkey test scenario for such endpoint:

- name: WHEN posting a file MUST return no error
  method: POST
  path: /accept-file.php
  headers:
    Content-Type: multipart/form-data; boundary=XXX
  request: |
    --XXX
    Content-Disposition: form-data; name="form_field_name"

    FormFieldValue
    --XXX
    Content-Disposition: form-data; name="userfile"; filename="filename.txt"
    Content-Type: application/octet-stream

    content of your file...
    --XXX--

  response:
    200: >
        {
          "post": {
            "form_field_name": "FormFieldValue"
          },
          "files": {
            "userfile": {
              "name": "filename.txt",
              "type": "application/octet-stream",
              "error": 0,
              "size": 23
            }
          }
        }

While experimenting, I've realised that the submitting file body cannot be binary (as it needs to be defined in YAML), so you can't submit an image for example.

from gonkey.

luza avatar luza commented on May 28, 2024

Little update: there is a way to incorporate binary data into YAML.

from gonkey.

JustSkiv avatar JustSkiv commented on May 28, 2024

@luza are you interested in implementation of native way to pass file? I can work on that.

from gonkey.

luza avatar luza commented on May 28, 2024

Sure.

Please, look at this task from the higher perspective first: how to natively support posting the form fields (www-form-urlencoded). Once it done, how to upload file within the form data (multipart/form-data).

Thanks for interest!

from gonkey.

luza avatar luza commented on May 28, 2024

Starting from #51, you can submit files.

from gonkey.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.