react-native-photo-editor
react-native-photo-editor copied to clipboard
After Saving File Get Error in IOS
Hello Team, after pressing the done button on IOS it will give me an error message. i have followed folllowing steps:
- i will get image link from server side.
- using RNFetchBlob i will store this image into local and get the following path: /var/mobile/Containers/Data/Application/C1AD606B-A508-4994-9736-5647350402FB/Documents/21_1_2020_15_36_22.jpg
- after doing proper changes when i press on DOne Button it will give me an error messsage. The error is as follows: Missing request token for request: <NSURLRequest: 0x283415040> { URL: file:///var/mobile/Containers/Data/Application/C1AD606B-A508-4994-9736-5647350402FB/Documents/21_1_2020_15_36_22.jpg }
Please help me to resolve this issue.
Are you using RNFS to seek the file path?
yes
var month = new Date().getMonth() + 1; var timestamp = new Date().getDate() + '' + month + '' +new Date().getFullYear() + '' + new Date().getHours() + '' + new Date().getMinutes() + '_' +new Date().getSeconds(); this.props.greetingStore.setUploadFileID(greeting_id); let photoPath = RNFS.DocumentDirectoryPath + '/' + timestamp + '.jpg'; RNFetchBlob.config({fileCache: true}) .fetch('GET', image_url) .then(resp => { RNFS.moveFile(resp.path(), photoPath) .then(() => { this.props.greetingStore.setgenrate_local_image_url('success'); this.methodcall(photoPath); }) .catch(err => { this.props.greetingStore.setgenrate_local_image_url('failed'); console.log('203 line greeting error::', err.message); }); }) .catch(err => { this.props.greetingStore.setgenrate_local_image_url('failed'); console.log('208 line greeting error::', err.message); });
this is my code
Looks good, could you share snippet of invoking the library Edit API, please.
here we call the library for open: methodcall(image_url_path) { RNPhotoEditor.Edit({ path: image_url_path, stickers: Platform.OS === 'ios' ? [] : GREETING_STICKERS,
hiddenControls: [],
colors: GREETING_COLOR,
onDone: response => {
console.log('on done');
console.warn('response::', image_url_path);
this.props.greetingStore.saveFileToServer(
Platform.OS === 'ios' ? image_url_path : response,
);
},
onCancel: () => {
console.log('on cancel');
},
});
}
image path URL return me like this /var/mobile/Containers/Data/Application/D61C7F96-7F7C-457F-A928-F8787073BB85/Documents/22_1_2020_14_7_58.jpg
saveFileToServer(filepath) {
this.upload_file_status = 'pending';
this.loader_Status = true;
var data = new FormData();
data.append('photo', {
uri: 'file://' + filepath, // your file path string
name: 'my_photo.jpg',
type: 'image/jpg',
});
fetch(DEFAULT_IMAGE_UPLOAD, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'multipart/form-data',
Authorization: Bearer ${GET_ASYNC_STORE.USER_ACCESS_TOKEN}
,
},
body: data,
})
.then(response => response.json())
.then(responseJson => {
runInAction(() => {
this.upload_file_status = 'success';
this.loader_Status = false;
var artCategoryId = responseJson[0].artCategoryId;
this.saved_file_name = responseJson;
console.log('Saved File Name:::', this.saved_file_name);
this.saved_file_id = this.upload_file_id;
});
})
.catch(error => {
this.upload_file_status = 'failed';
this.loader_Status = false;
console.error(error);
});
}
this is an API Call