0

我正在发送一个动作来上传视频。该操作应该运行传奇,但它没有按预期工作。传奇有时会运行,有时则不会。我不知道saga不会听动作的确切情况。我们拥有控制台日志的第一行handleCompressAndUploadVideo没有执行。我想每当我重新加载应用程序时它都会工作,但之后的后续视频上传请求有时不会运行传奇,但情况并非总是如此。

export function* handleCompressAndUploadVideo(action) {
  console.log("-------------INSIDE ACTION")
  const {
    path,
    options,
    index,
    apiData,
    data,
    draftVideoId,
    videoId,
  } = action.payload;
  const userToken = yield call(getItemFromStorgae, 'usertoken');
  const isConnected = yield call(checkInternet);
  // yield call(compress, path, options);
  const uri = path; //comdata && comdata.source ? comdata.source : path ? path : null;
  const file = {
    uri: uri,
    name: `${index}.mp4`,
    type: 'video/mp4',
  };
  const vId = data.data.data._id;
  apiData.append('video', file);
  apiData.append('videoId', vId);
  let status;
  console.log("isConnected: ", isConnected)
  if (isConnected) {
    try {
      console.log("before api")
      const response = yield call(
        fetchapi,
        'api/service/upload-video',
        'post',
        apiData,
        userToken,
      );
      console.log("after api")
      status = response.data.status;
      if (response.data.status) {
        yield put(Actions.uploadSuccess(index));
      }
    } finally {
      console.log("here finally", status)
      if (!status) {
        yield put(Actions.setLoadingFalse(draftVideoId, videoId));
        sweetalert('upload error', 'error');
      }
    }
  } else {
    yield put(Actions.setLoadingFalse(draftVideoId, videoId));
    sweetalert('upload error', 'error');
  }
}

function* MentorSaga() {
  yield all([
    yield takeLatest(ActionTypes.SET_LOADING_FALSE, uploadFailed),
    yield takeLatest(
      ActionTypes.COMPRESS_AND_UPLOAD_VIDEO,
      handleCompressAndUploadVideo,
    ),
  ]);
}

4

1 回答 1

0

Vladimir Serykh刚刚回答了这个问题,但直到后来我才注意到。

尝试在 takeLatest 之前删除 yield。那里不需要它,因为 takeLatest 不是生成器。

于 2021-07-14T14:51:12.470 回答