AgoraIO / RTM

143 stars 160 forks source link

Error code 2 - Invalid message params type when call function createMediaMessageByUploading() #175

Open thuantvDr4 opened 2 years ago

thuantvDr4 commented 2 years ago

I used agora-rtm-sdk for react-native project. .feature chat with text it work fine. .feature chat with send image and file it error above,

this is error i am facing: ERROR RTM:ERROR Error Code 2: createMediaMessageByUploading failed with args: {"lastModified":1650011903760,"lastModifiedDate":"2022-04-18T15:56:36.393+0700","name":"D76A0851-0B93-452D-A5CB-0F66840C8223.png","size":23162,"type":"image / png"}

---send-img:err: [RtmInvalidArgumentError: Error Code 2 - Invalid message params type.]

more info: "agora-rtm-sdk": "^1.4.2", "react-native": "0.67.4",

please help me some solution. thanks a lot!

plutoless commented 2 years ago

hi @thuantvDr4 could you pls share how you call the api or if you could provide a minimal reproducible project it would help a lot.

thuantvDr4 commented 2 years ago

hi @thuantvDr4 could you pls share how you call the api or if you could provide a minimal reproducible project it would help a lot.

this is my function & code

const initRtm =async ()=>{ if(channel){ await client.login({uid: userInfo?.uid, token: userInfo?.token}); await channel.join(); await client.setLocalUserAttributes({ name: userInfo.name, color: userInfo.color, }); }

}

//---initial client & channel
useEffect(()=>{
    try {
        const clientNew = AgoraRTM.createInstance(userInfo?.appId,{});
        const channelNew = clientNew.createChannel(userInfo?.channel);
        setClient(clientNew);
        setChannel(channelNew);
    }catch (e) {
        console.log('--Error:',e)
    }
},[])

const sendChannelFileMsg =async(fileBlob, fileName)=>{
    try {
        await client
            .createMediaMessageByUploading(fileBlob, {
                messageType: 'file',
                fileName: fileName,
                description: "send file",
            })
            .then((response) => {
                console.log('---createMediaMessageByUploading:', response)
                const fileCreated = client.createMessage({
                    mediaId: response.mediaId, // Your mediaId
                    messageType:'file',
                    fileName: fileName,
                    description: "send file",
                });
                // sendChannelMessage(fileMessage, true);
                console.log('---fileCreated:', fileCreated)
            });
    }catch (e) {
        console.log('---send-file:err:',e)
    }
}
plutoless commented 2 years ago

could you pls try "FILE" instead of "file"?