将拾取的照片转换为base64时出现问题。需要它用于Firebase。
这是第一次尝试:
ImagePickerManager.showImagePicker(options, (response) => {
if (response.uri) {
var uri = response.uri;
ImageStore.getBase64ForTag(
uri,
function (imageData) {
this.setState({
imageData: imageData,
eventImage: { uri: 'data:image/jpeg;base64,' + imageData, isStatic: true }
});
}.bind(this),
function (error) { console.log('uri getBase64ForTag error', error);}
);
出现此错误:
2016-06-08 19:08:47.980 [info][tid:com.facebook.react.JavaScript] 'uri getBase64ForTag error', { code: 'ERCTERRORDOMAIN0',
message: 'Invalid imageTag: /var/mobile/Containers/Data/Application/{HASH 1}/Library/Caches/{HASH 2}.jpg',
nativeStackIOS:
[ '0 Project 0x00000001001841cc RCTJSErrorFromCodeMessageAndNSError + 148',
'1 Project 0x00000001001840f8 RCTJSErrorFromNSError + 264',
'2 Project 0x000000010011ede8 __41-[RCTModuleMethod processMethodSignature]_block_invoke_2.203 + 112',
'3 Project 0x00000001001e324c -[RCTImageStoreManager getBase64ForTag:successCallback:errorCallback:] + 304',
'4 CoreFoundation 0x0000000183004a60 <redacted> + 144',
'5 CoreFoundation 0x0000000182efc488 <redacted> + 284',
'6 CoreFoundation 0x0000000182f00db0 <redacted> + 60',
'7 Project 0x0000000100120928 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 1684',
'8 Project 0x000000010016d2bc -[RCTBatchedBridge _handleRequestNumber:moduleID:methodID:params:] + 712',
'9 Project 0x000000010016c1d4 __33-[RCTBatchedBridge handleBuffer:]_block_invoke.460 + 1232',
'10 libdispatch.dylib 0x00000001006c5a7c _dispatch_call_block_and_release + 24',
'11 libdispatch.dylib 0x00000001006c5a3c _dispatch_client_callout + 16',
'12 libdispatch.dylib 0x00000001006d2554 _dispatch_queue_drain + 1036',
'13 libdispatch.dylib 0x00000001006c972c _dispatch_queue_invoke + 464',
'14 libdispatch.dylib 0x00000001006c5a3c _dispatch_client_callout + 16',
'15 libdispatch.dylib 0x00000001006d4c9c _dispatch_root_queue_drain + 2344',
'16 libdispatch.dylib 0x00000001006d4364 _dispatch_worker_thread3 + 132',
'17 libsystem_pthread.dylib 0x0000000182c61470 _pthread_wqthread + 1092',
'18 libsystem_pthread.dylib 0x0000000182c61020 start_wqthread + 4' ],
domain: 'RCTErrorDomain' }
还尝试了这种方法,使用ReadImageData:
ImagePickerManager.showImagePicker(options, (response) => {
if (response.uri) {
var uri = response.uri;
ReadImageData.readImage(
uri,
function (imageData) {
this.setState({
imageData: imageData,
eventImage: { uri: 'data:image/jpeg;base64,' + imageData, isStatic: true }
});
}.bind(this)
// function (error) { console.log('Event image getBase64ForTag error', error);}
);
但是却得到了这个错误:
2016-06-08 22:42:28.368 Project[1647:630750] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(0x182ffedb0 0x182663f80 0x182ee21a0 0x182eedc48 0x100089730 0x18cf437cc 0x100711a7c 0x100711a3c 0x100720c9c 0x100720364 0x182c61470 0x182c61020)
libc++abi.dylib: terminating with uncaught exception of type NSException
我做错了什么? :)