Closed leonyhenn closed 4 years ago
import { ChatManager, TokenProvider } from '@pusher/chatkit/react-native';
import ImagePicker from 'react-native-image-crop-picker';
const chatManager = new ChatManager({
tokenProvider: new TokenProvider({
url: YOUR_PUSHER_TOKEN_PROVIDER_URL,
// ...
}),
});
chatManager.connect().then(user => {
// open and select an image from your phone gallery
ImagePicker.openPicker()
.then(res => {
user.sendMessage({
text: ' ', // cannot be empty string or null
roomId: this.state.roomId, // your pusher room id
attachment: {
file: {
uri: res.path,
type: 'image/jpeg',
name: 'image.jpg',
},
name: 'myfile.jpg',
},
});
})
.catch(e => {
console.error(e);
});
});
thanks @gianpaj , it worked!
@leonyhenn Are you able to access these files after sometime ? Can you help me out in getting these files back? I try immediately after posting the files, it works fine. But after a few days, it says that the key doesn't exist. Can you help me out ?
Closing this because it's more about the quirks of how files objects work in react native than about an issue with this SDK. Please contact support if you're running in to problems uploading files on react native and we'll prioritise getting something added to the docs.
Never used react on web before so having trouble understanding the example, would appreciate if there is an example for uploading file attachments in React Native.