Upload File from MediaLibrary

#1

I’m using MediaLibrary to create my own image/file picker.

Upon selecting the file i’d like to upload it via axios to my backend.

I can get image files to work properly.

However I can’t seem to get video’s to upload correctly the server keeps thinking the mime type is image/jpeg vs video/mp4.

I’m using the simulator for testing and I’ve added my own mp4 file to the photo library.

I’m using the following to generate the mime/type to upload however I think the asset.uri is not returning the actual video file it’s returning the screenshot version of the video instead.

I’ve tried to use MediaLibrary.createAssetAsync to get the localUri however it never seems to return that either.

let filename = file.split('/').pop();
filename = filename.split('?').shift();
let match = /\.(\w+)$/.exec(filename);
let fileType = match ? `${type}/${match[1].toLocaleLowerCase()}` : `${type}`;

formData.append('file', {
            uri: file,
            name: filename,
            type: fileType,
});

Any help would be greatly appreciated. I know I can use the ImagePicker library however i’d like to use a custom UI and have the ability to easily switch between pictures and videos to give a better experience to the users.

Thanks,

#2

@vialware Did you ever find a solution to this?

closed #3

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