0

I try upload image on server with this code:

    updateAvatar(token, photo) {
    return postImage(
      "http://lk.skilla.ru/myapi/updateAvatar",
      [
        {
          name: "avatar",
          filename: "avatar.jpg",
          type: "image/jpg",
          data: Platform.OS === "android" ? RNFetchBlob.wrap(photo) : photo,
        },
      ],
      token
    );
  },
const postImage = (url, params, token) => {
  return RNFetchBlob.config({ fileCache: true, appendExt: "jpg" })
    .fetch(
      "POST",
      url,
      { Authorization: token, "Content-Type": "multipart/form-data" },
      params
    )
    .then((res) => {
      console.log("response");
      console.log(res.text());
        return Platform.OS === 'android' ? 'file://' + res.path() : '' + res.path()
    })
    .catch((error) => console.log(error));
};

And on android all work fine, but on iOS file returned by RN-Fetch-Blob does not exist. How to wrap url on iOS? RNFetchBlob.wrap don't work

1 Answer 1

3

This is how I got it to work for me.

const filePath = Platform.OS === 'ios'
    ? res.path().replace('file:///', '').replace('file://', '')
    : res.path().replace('file://', '').replace('file:/', '');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.