Since I did not receive a response, I continued to dig the documentation on the phone and finally received a response. The following are my code samples. note that the method of identifying the file extension is taken from here
I have a control button on my html (in the phoneGap application), as shown below, anyone can link to the phoneGap documentation from here . This is so helpful. I used version 2.9.0
<button onclick="getPhoto(Camera.pictureSource.PHOTOLIBRARY);">From Photo Library</button>
javascript getPhoto(),
function getPhoto(source)
{
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 100,
destinationType: navigator.camera.DestinationType.NATIVE_URI, sourceType: source });
}
, ,
function onPhotoURISuccess(imageURI) {
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.src = imageURI;
checkFileExtention(imageURI);
}
checkFileExtention() .
- (NSString *)contentTypeForImageData:(NSString *)imageUrl
{
NSURL *imageURL = [NSURL URLWithString:imageUrl];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
uint8_t c;
[imageData getBytes:&c length:1];
switch (c)
{
case 0xFF:
return @"image/jpeg";
case 0x89:
return @"image/png";
case 0x47:
return @"image/gif";
case 0x49:
case 0x4D:
return @"image/tiff";
case 0x42:
return @"@image/bmp";
}
return nil;
}
FILE_URI URI,
://localhost/Users/user/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/B50E3AD6-74F8-43F6-9F91-F28D2B06DF62/tmp/cdv_photo_116.jpg
-, , jpg
NATIVE_URI, :
? ://asset/asset.JPG ID = 5CF16D20-9A80-483A-AC1C-9692123610B1 & = JPG
, uri JPG, JPG, .
, , uri contentTypeForImageData funtion,