Strapi-React Native-上传文件

时间:2018-09-28 08:48:07

标签: reactjs react-native strapi

我正在尝试将图像从我的Android应用程序上传到Strapi API。我得到responseJsonFromServer = "True"。但是,该图片尚未上传。

我是React Native的初学者。我会使用错误的from-data吗?

      Insert_Files_Into_DataBase = () => {

        let formdata = new FormData();
        formdata.append("files", "../icons/ImageTestUpload.png");

      () => {
        console.log("fetch");
        fetch("http://192.168.0.101:1337/upload", {
          method: "POST",
          headers: {
            "Content-Type": "multipart/form-data",
            Authorization: "Bearer " + this.props.userToken.jwt
          },
          body: formdata
        })
          .then(response => response.json())
          .then(responseJsonFromServer => {
            alert(responseJsonFromServer + "Image1 OK!");
            console.log("Insert Picture: ", responseJsonFromServer); //Return true 
          })
          .catch(error => {
            console.error(error);
            this.setState({ ActivityIndicator_Loading: false });
          });
      }
    );
  };

0 个答案:

没有答案