use @sendbird/chat
got an error “Cannot read property ‘sendingStatus’ of null” or “InvalidParameters” when use channel.sendFileMessage()
use expo, expo-image-picker, expo-file-system
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
base64: true,
});
const fileInfo = await FileSystem.getInfoAsync(result.uri)
const localUri = result.uri;
const filename = localUri.split("/").pop();
const match = filename ? /\.(\w+)$/.exec(filename) : "";
const type = match ? `image/${match[1]}` : `image`;
function dataURItoBlob(dataURI) {
// convert base64/URLEncoded data component to raw binary data held in a string
let byteString;
if (dataURI.split(',')[0].indexOf('base64') >= 0)
byteString = atob(dataURI.split(',')[1]);
else
byteString = unescape(dataURI.split(',')[1]);
// separate out the mime component
let mimeString = type;
// write the bytes of the string to a typed array
let ia = new Uint8Array(byteString.length);
for (let i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ia], {type:mimeString});
}
const blob = dataURItoBlob(result.base64)
const newFile = new File([blob], filename, { type });
return props.onSend([{
size: fileInfo.size,
file: newFile,
name: filename,
type,
fileInfo,
blob,
base64: `data:image/jpg;base64,${result.base64}`,
fileUrl: result.uri,
width: result.width,
height: result.height,
}])
try use file, base64, fileUrl, blob, fileInfo all of them not working… Please help, what I do wrong?