본문에 form-data
이라는 파일을 업로드합니다. ajax
을 사용하면 올바르게 작동하지만 redux-saga
에서 같은 작업을 시도하면 작동하지 않으며 실패합니다. 내가 도대체 뭘 잘못하고있는 겁니까? 아약스에서redux saga를 사용하여 양식 필드 파일 업로드
, 여기
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);
}
});
내 사가 코드 : 나는 REDUX - 사가에서 동일한 작업을 수행 할 때
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);
}
}
Looks ok. 'fetchJson' 함수는 무엇입니까? 약속을 되 돌리는가? – wostex