Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _uploadFile = function(url, path, extra_data) {
- return new Promise ((resolve, reject) => {
- console.log("URL:", url, "Path: ", path, "Data: ", extra_data);
- const data = new FormData();
- if (path !== '') {
- const _type = mime.getType(path);
- const _ext = mime.getExtension(_type);
- data.append('ext', _ext); // you can append anything.
- data.append('file', {
- uri: path,
- type: _type, // or photo.type
- name: 'testPhotoName'
- });
- }
- data.append('extra_data', JSON.stringify(extra_data));
- console.log("DATA: ", data);
- fetch(Base.API_BASE_URL + url, {
- method: 'post',
- body: data
- })
- .then((response) => response.json())
- .then(resp => {
- console.log(resp);
- resolve(resp);
- })
- .catch(err => {
- console.log("[uploadFile] [Catch] : ", err);
- reject(err);
- });
- });
- }
- //EditProfile
- async pickImage() {
- if (this.state.is_editable) {
- ImagePicker.openPicker({
- width: 300,
- height: 400,
- cropping: true
- }).then(result => {
- let data = {
- user_id: this.state.user.id
- };
- uploadFile('change_profile', result.path, data)
- .then(resp => {
- if (resp.status === 'success') {
- console.log("RESPONSE: ", resp);
- this.setState({ user: resp.data });
- setItem('user', resp.data);
- } else {
- showErrorToast(resp.message);
- }
- })
- .catch(err => {
- console.log("ERROR = ", err);
- });
- });
- }
- }
Add Comment
Please, Sign In to add comment