Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Pass FormData using feathers-rest-client #1744

Copy link
Copy link
@bwgjoseph

Description

@bwgjoseph
Issue body actions

Hi,

I would like to use feathers-rest-client and send data through rest with attachments (FormData), together with the rest of the body. The application is setup and configure with both rest and socket client. If there are data with attachments, it will use rest client to communicate with server, otherwise, use socket client.

I have configured feathers-rest-client to pass data to server.
feathers-rest-client is configured something like this.

const app = feathers();
const restClient = rest('http://localhost:3030')
app.configure(restClient.fetch(window.fetch));

There's a form for user to fill up some fields, and add some attachment. After which I hope to call the test endpoint using feathers-rest-client as such..

fData = {
 field1: 'test',
 field2: 'test2',
 file: [attachments] // this is a FormData
}

// Also tried
FormData fData = new FormData();
fData('field1', 'test');
fData('field2', 'test2');
fData('file', attachments);
restClient.service('test').create(fData);

Server has something like this.

app.use('/test', multer.array('file'), setReqFileToFeatherFile(), createService());

However, no matter how I change it, I am not able to get and extract the data at the server side. Meaning to say, I think the data is set wrongly, and hence, multer does not know how to extract/decode from the correct field to get the attachments and so on.

But If I were to use POSTMAN to send a request to my endpoint, server is able to extract/decode the data correctly. Meaning to say, the file are passed through multer to extract the attachments (available in feathers.params.files), and the body are able to retrieve from context.data.

image

Any idea what am I doing wrong?

Thanks.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.