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

Implement multipart/form-data to support html file upload #14

Closed
tpmccallum opened this issue May 21, 2020 · 2 comments
Closed

Implement multipart/form-data to support html file upload #14

tpmccallum opened this issue May 21, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@tpmccallum
Copy link
Contributor

tpmccallum commented May 21, 2020

This will be useful for calling functions of wasm executable. Details below.

@tpmccallum tpmccallum added the enhancement New feature or request label May 21, 2020
@tpmccallum
Copy link
Contributor Author

tpmccallum commented Jun 4, 2020

/api/multipart/run/:wasm_id/:function_name

When using multipart as part of a wasm executable's function execution the following logic needs to be implemented

URL

  • when the caller passes a url as the value of form's text key, check to see what the fetch returns
  • if the URL (as seen above) returns a text/plain or application/json body, then pass this into SSVM as string
  • if the URL returns anything else, pass this into SSVM as as Buffer

File

  • when the caller passes a file as shown below fetch the file as Buffer (default fetch type of nodejs fs readFile is Buffer)
--form 'first_file=@/Users/tpmccallum/data.txt'
  • ask about whether or not it would be preferred if the default Buffer is converted to String before being passed into SSVM NAPI

Order of arguments being passed into SSVM NAPI

The caller can pass any number of arguments into the Joey request, these will be passed into SSVM NAPI by Joey. The order and the data type of these arguments will be known by the Rust Wasm application (there is always an implicit agreement/understanding between the caller and the Rust Wasm code that they are calling)

  • Need to test that the order in which multipart data is given in the HTTP request is maintained right through to Nodejs's Formidable middleware
    For example, if a caller provides two URLs, one which is string and the other which is Buffer, does Nodejs's Formidable middleware process these in the order given?
    It is possible that the middleware will provide them in the order that they are fetched (smaller data gets in first) or in no particular order at all. If this is the case Joey will not be able to pass multiple parameters into SSVM NAPI in the right order. It may be necessary to use pre-defined explicit naming convention for keys used in multipart data requests.
    For example
--form 'joey_remote_data_url_1=https://raw.githubusercontent.com/tpmccallum/test_endpoint2/master/raw_file_example.txt'
--form 'joey_remote_data_url_2=https://raw.githubusercontent.com/tpmccallum/test_endpoint2/master/raw_file_example.txt'

@tpmccallum
Copy link
Contributor Author

This is now implemented and working.
There are no race conditions due to some new custom code
The data types and order are always maintained and ssvm is able to execute any combination of multipart requests
https://web.postman.co/collections/4967217-84b93d68-2073-4f51-bde3-68f19de57c62?version=latest&workspace=6683d8e5-f543-4751-8871-aeceebf90811#b0be4952-8322-4eff-bb09-959d6fff9de9

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

No branches or pull requests

1 participant