Reputation: 3052
In my app i want to be able to upload an image from gallery or camera and be able to upload and set it in to an image view.Just like the feature in Facebook,what app etc.
Suggest me a proper way to do it,a good library(a mostly used one)might be helpful.
Upvotes: 1
Views: 1733
Reputation: 5684
These are to many things still, here is the library for image select from gallary and camera,
https://github.com/react-community/react-native-image-picker
and here is the code to upload image using fetch.
var photo = {
uri: user.profilePicture,
type: 'image/jpeg',
name: 'photo.jpg',
};
var form = new FormData();
form.append("ProfilePicture", photo);
fetch(
Constants.API_USER + 'me/profilePicture',
{
body: form,
method: "PUT",
headers: {
'Content-Type': 'multipart/form-data',
'Authorization': 'Bearer ' + user.token
}
}
).then((response) => response.json())
.catch((error) => {
alert("ERROR " + error)
})
.then((responseData) => {
alert("Succes "+ responseData)
}).done();
Upvotes: 4