Skip to content

Instantly share code, notes, and snippets.

@leonj1
Created November 15, 2018 13:31
Show Gist options
  • Save leonj1/17ed629d97d56dfac9bfab7178c49e35 to your computer and use it in GitHub Desktop.
Save leonj1/17ed629d97d56dfac9bfab7178c49e35 to your computer and use it in GitHub Desktop.
function* uploadImage(action) {
try {
let _room = yield select(getRoom);
let _user = yield select(getUser);
const {image, fileName} = action.payload;
let headers = {
'Token': _user.token,
'FileName': fileName,
};
const contents = yield call(axios.post, backend + "/image/" + _room.roomId, image, {headers: headers});
let _actionType = contents.status === 200 ? UPLOAD_IMAGE_SUCCESS : UPLOAD_IMAGE_FAILURE;
yield put({
type: _actionType,
toast: {
show: true,
contents: contents.data,
duration: 2500,
color: "green"
},
});
yield put({
type: FETCH_MESSAGES_OFFSET_LIMIT_REQUEST,
payload: {
offset: 0,
limit: 25
}
});
} catch (e) {
let _data = 'problem sending image';
if (e && e.response) {
_data = e.response.data;
}
yield put({
type: UPLOAD_IMAGE_FAILURE,
toast: {
show: true,
contents: _data,
duration: 2500,
color: "red"
},
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment