pusher / chatkit-client-js

JavaScript client SDK for Pusher Chatkit
https://pusher.com/chatkit
MIT License
90 stars 15 forks source link

Require an example for React Native attachment upload #88

Closed leonyhenn closed 4 years ago

leonyhenn commented 6 years ago

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.

gianpaj commented 6 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);
    });
});
leonyhenn commented 6 years ago

thanks @gianpaj , it worked!

vishesh774 commented 5 years ago

@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 ?

callum-oakley commented 4 years ago

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.