2017-07-25 73 views
1

在我的應用程序中,我希望能夠從圖庫或相機中上傳圖片,並能夠上傳並設置圖片視圖。就像 Facebook的功能,什麼應用程序等圖片上傳和裁剪的React-Native庫(支持android和ios)

建議我一個正確的方法來做到這一點,一個好的圖書館(一個最常用的圖書館)可能會有所幫助。

回答

2

這些都是現在很多東西還在,這裏是圖像庫從GALLARY和相機選擇,

https://github.com/react-community/react-native-image-picker

,這裏是用獲取上傳圖像的代碼。

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(); 
+0

作物特徵呢? –

+0

試試這個庫。 https://github.com/ivpusic/react-native-image-crop-picker –

+0

harshal你可以給我一些你可能已經實現這個庫的項目的參考代碼嗎? –