Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thuantvDr4 opened this issue Apr 18, 2022 · 3 comments

Comments

@thuantvDr4
Copy link

thuantvDr4 commented Apr 18, 2022

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
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants