diff --git a/doc/index.md b/doc/index.md index 5875a93..d7016b0 100644 --- a/doc/index.md +++ b/doc/index.md @@ -33,7 +33,7 @@ base64-encoded `String`, or as the URI for the image file. The method itself returns a `CameraPopoverHandle` object that can be used to reposition the file selection popover. - navigator.camera.getPicture( cameraSuccess, cameraError, [ cameraOptions ] ); + navigator.camera.getPicture( cameraSuccess, cameraError, cameraOptions ); ### Description diff --git a/src/android/CameraLauncher.java b/src/android/CameraLauncher.java old mode 100755 new mode 100644 index 96c15da..7196fcf --- a/src/android/CameraLauncher.java +++ b/src/android/CameraLauncher.java @@ -380,14 +380,19 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect else if (destType == FILE_URI || destType == NATIVE_URI) { if (this.saveToPhotoAlbum) { Uri inputUri = getUriFromMediaStore(); - //Just because we have a media URI doesn't mean we have a real file, we need to make it - uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova))); + try { + //Just because we have a media URI doesn't mean we have a real file, we need to make it + uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova))); + } catch (NullPointerException e) { + uri = null; + } } else { uri = Uri.fromFile(new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg")); } if (uri == null) { this.failPicture("Error capturing image - no media storage found."); + return; } // If all this is true we shouldn't compress the image. @@ -420,14 +425,14 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect exif.writeExifData(); } if (this.allowEdit) { - performCrop(uri); - } else { - // Send Uri back to JavaScript for viewing image - this.callbackContext.success(uri.toString()); - } + performCrop(uri); + } else { + // Send Uri back to JavaScript for viewing image + this.callbackContext.success(uri.toString()); + } } - // Send Uri back to JavaScript for viewing image - this.callbackContext.success(uri.toString()); + } else { + throw new IllegalStateException(); } this.cleanup(FILE_URI, this.imageUri, uri, bitmap); @@ -641,7 +646,7 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException { // If retrieving photo from library else if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) { - if (resultCode == Activity.RESULT_OK) { + if (resultCode == Activity.RESULT_OK && intent != null) { this.processResultFromGallery(destType, intent); } else if (resultCode == Activity.RESULT_CANCELED) { @@ -735,11 +740,11 @@ private String ouputModifiedBitmap(Bitmap bitmap, Uri uri) throws IOException { Uri uri; try { uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); - } catch (UnsupportedOperationException e) { + } catch (RuntimeException e) { LOG.d(LOG_TAG, "Can't write to external media storage."); try { uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); - } catch (UnsupportedOperationException ex) { + } catch (RuntimeException ex) { LOG.d(LOG_TAG, "Can't write to internal media storage."); return null; } diff --git a/src/ios/CDVCamera.h b/src/ios/CDVCamera.h index 744ae7f..63deac9 100644 --- a/src/ios/CDVCamera.h +++ b/src/ios/CDVCamera.h @@ -84,7 +84,6 @@ typedef NSUInteger CDVMediaType; * quality: integer between 1 and 100 */ - (void)takePicture:(CDVInvokedUrlCommand*)command; -- (void)postImage:(UIImage*)anImage withFilename:(NSString*)filename toUrl:(NSURL*)url; - (void)cleanup:(CDVInvokedUrlCommand*)command; - (void)repositionPopover:(CDVInvokedUrlCommand*)command; diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m index ab99297..fc1afb4 100644 --- a/src/ios/CDVCamera.m +++ b/src/ios/CDVCamera.m @@ -533,48 +533,6 @@ static NSSet* org_apache_cordova_validArrowDirections; return newImage; } -- (void)postImage:(UIImage*)anImage withFilename:(NSString*)filename toUrl:(NSURL*)url -{ - self.hasPendingOperation = YES; - - NSString* boundary = @"----BOUNDARY_IS_I"; - - NSMutableURLRequest* req = [NSMutableURLRequest requestWithURL:url]; - [req setHTTPMethod:@"POST"]; - - NSString* contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; - [req setValue:contentType forHTTPHeaderField:@"Content-type"]; - - NSData* imageData = UIImagePNGRepresentation(anImage); - - // adding the body - NSMutableData* postBody = [NSMutableData data]; - - // first parameter an image - [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; - [postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"upload\"; filename=\"%@\"\r\n", filename] dataUsingEncoding:NSUTF8StringEncoding]]; - [postBody appendData:[@"Content-Type: image/png\r\n\r\n" dataUsingEncoding : NSUTF8StringEncoding]]; - [postBody appendData:imageData]; - - // // second parameter information - // [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; - // [postBody appendData:[@"Content-Disposition: form-data; name=\"some_other_name\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; - // [postBody appendData:[@"some_other_value" dataUsingEncoding:NSUTF8StringEncoding]]; - // [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r \n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; - - [req setHTTPBody:postBody]; - - NSURLResponse* response; - NSError* error; - [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error]; - - // NSData* result = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error]; - // NSString * resultStr = [[[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding] autorelease]; - - self.hasPendingOperation = NO; -} - - - (CLLocationManager *)locationManager { if (locationManager != nil) {