DocumentPicker - How can I get the file type?

Please provide the following:

  1. SDK Version: 36.0.0
  2. Platforms(Android/iOS/web/all): Android

I need to get a BLOB file with it’s extension in order to upload to a cloud service.

When I use DocumentPicker.getDocumentAsync();

The response looks like this:

Object {
  "name": "NegoNey_Destroi_Catedral",
  "size": 471595,
  "type": "success",
  "uri": "content://com.android.providers.media.documents/document/audio%3A558",
}

||

Object {
  "name": "NegoNey_Destroi_Catedral",
  "size": 471595,
  "type": "success",
  "uri": "file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540<user>%252F<app>/DocumentPicker/dd37d0d0-ac5c-4952-a433-eda76281f2a3.",
}

The extension should be .mp3, but It’s not on the response.

3 Likes

I was looking for the same thing since a long time. Any developments on this?

I ended up doing this way:

 __convertToBlob = async audioUri => {
    try {
      const fetchedAudio = await fetch(audioUri);
      const blob = await fetchedAudio.blob();

      if (blob.size <= this.maxBlobSize) {
        return blob;
      }
    } catch (error) {
      console.log(error.message);
    }
  };

This will return a blob type, then, getting the file type is as simple as:

__getFileExtension = blob => {
    const { type } = blob;

    return type.substr(type.indexOf("/")).replace("/", ".");
  };
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.