从React Native成功上传到Cloudinary的图像不会返回URL

问题描述

我正在尝试将图像从React Native应用上传到Cloudinary。 该图像显示在仪表板上,但是我没有找到secure_url。

这是我的代码:

  async uploadImage(photo: ImagePickerResponse,id: string): Promise<string> {
    return new Promise<string>(async (resolve,reject) => {
      const uploadPreset = 'bbbbbb';
      const cloudName = 'aaaaa';

      const body = new FormData();
      const uri: string =
        Platform.OS === 'android' ? photo.uri : photo.uri.replace('file://','');
      const type = photo.type;
      const name = `eMia${id}.jpeg`;
      const file = {uri,type,name};
      body.append('file',file);
      body.append('upload_preset',uploadPreset);
      body.append('cloud_name',cloudName);
      const url = `https://api.cloudinary.com/v1_1/${cloudName}/image/upload`;

      fetch(url,{method: 'POST',body})
        .then((res) => {
          // I don't have Body here so i don't have the image url :(
          console.log(res);
          res.json();
        })
        .then((json) => {
          console.log(json);
          const url = json.secure_url;
          console.log(url);
          resolve(url);
        })
        .catch((err) => {
          reject(err);
        });
    });
  }

响应:

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)