I am uploading a file in the body as form-data
. Using ajax
it works fine but when I try to do the same in redux-saga
, it does not work and fails. What am I doing wrong?
In ajax,
let upload = ajax.post(PathHelper.apiPath + '/create/text').field('file', file);
upload.end((err, response) => {
if (err) {
console.log('Error Encountered', err);
}
if (response) {
const imageResponse = response.body;
console.log('imageresponse: ', imageResponse);
}
});
Here is my saga code:
export function* fetchText(text) {
const formData = new FormData();
formData.append('file', text.data);
console.log('formData: ', formData);
try {
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: formData
};
const response = yield call(fetchJson, PathHelper.apiPath + '/create/text', options);
console.log('response: ', response);
} catch (err) {
console.log('Error saving your image', err);
}
}