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

Please help with uploading images not in Camera Roll #3

Open
pakicoder123 opened this issue Jul 29, 2017 · 2 comments
Open

Please help with uploading images not in Camera Roll #3

pakicoder123 opened this issue Jul 29, 2017 · 2 comments

Comments

@pakicoder123
Copy link

Hi, firstly I would like to say I really like this library and appreciate how well made it is.

The issue I'm having is that I don't know how to post a status with an image without using the camera roll. Is there anyway to get an image from a url on the internet and post that image to a twitter status along with some text? Please point me in the right direction, I couldn't find anything in your documentation.

Thank you so much for your time

@Piroro-hs
Copy link
Owner

Piroro-hs commented Aug 15, 2017

React Native currently lacks Blob implementation, so getting an image from a url on the internet and posting that to a twitter is a little bit complicate work.

First, we need a file downloading library such as react-native-fetch-blob, react-native-fs, etc to download an image and get the uri of it. Below sample uses react-native-fetch-blob.

let imageUri = '';

RNFetchBlob
  .config({
    fileCache: true,
  })
  .fetch('GET', 'image url')
  .then((resp) => {
    const imagePath = resp.path();
    imageUri = `file://${imagePath}`;
  });

Then we can use this imageUri to create Object with uri property and pass it to rest.post().

rest.post('media/upload', {media: {uri: imageUri}})
  .then(({media_id_string}) => rest.post('statuses/update', {status: 'test', media_ids: media_id_string}));

When React Native gets support of Blob, I'll add some helper methods for media uploading.
(facebook/react-native#11417, facebook/react-native#11573)

@pakicoder123
Copy link
Author

Thank you so much! I've been working countless hours on this, day and night, I appreciate the reply very much. Will the code you wrote above work as is or would I need to make any changes to it? Please let me know and again I would like to say that I appreciate your help and the wonderful library you've made.

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