How to use a local file uri, obtained through DocumentPicker, in imageManipulator. Using expo

Viewed 87

Ok so im using expo to manage my react native app, and in one of my functionalities, i allow the user to select a file that is going to be uploaded, the thing is the user can select any type of file, therefore I'm using DocumentPicker, so the user can select the file he wants the upload, the problem is due to some server capacity issues, I am required to use ImageManipulator in order to manipulate the image, so it betters fits under the available space, but whenever I provide the file uri to the ImageManipulator i get an error "[Unhandled promise rejection: Error: Exception in HostFunction: Malformed calls from JS: field sizes are different.]". Here is my code:

let result = await DocumentPicker.getDocumentAsync({
        type:"*/*" ,
    });
if (!result.cancelled) {
        const fileType=result.uri.substr(result.uri.lastIndexOf('.') + 1);

        if(fileType==="jpg" || fileType==="png" || fileType==="gif"){
             const manipResult = await ImageManipulator.manipulateAsync(
                     result.uri,
                     [{ resize: { width: manipulatedWidth, height: manipulatedHeight } }],
                     { compress: 0.7, format: ImageManipulator.SaveFormat.JPEG }
             );
        }
}

Whenever i use ImagePicker instead of DocumentPicker, i don't get this error, but in this case i really need to use DocumentPicker so the user can choose whichever file to upload.

0 Answers
Related