function is returing {"_U": 0, "_V": 0, "_W": null, "_X": null} on calling

Viewed 272

I'm uploading audio to cloudinary with expo. Audio is uploading successfully with this code and returning all the fields.


  //send audio to cloudinary
  async uploadAudioToCloudinary() {
    let base64Url = `data:audio/m4a;base64,${this.state.recordingBase64}`; //add base64
    let apiUrl = "https://api.cloudinary.com/v1_1/dxnblz2x7/upload";

    let data = {
      file: base64Url,
      upload_preset: "*******",
      resource_type: "video",
    };

    const response = await fetch(apiUrl, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify(data),
    });

    const resData = await response.json();
    return resData.url;
  }

But when I'm calling this in another function to get the secure_url like this, its returning Promise {"_U": 0, "_V": 0, "_W": null, "_X": null}

const record = this.uploadAudioToCloudinary();
console.log("RECORD", record); //Promise {"_U": 0, "_V": 0, "_W": null, "_X": null}
1 Answers

As stated in your console.log, record is a promise, you must wait for it to be resolved.

const record = await this.uploadAudioToCloudinary();
Related