45 Commits

Author SHA1 Message Date
Gastón Cerioni
bd3e0f299f removes check code for folders 2021-12-15 17:23:02 -03:00
Stefano Magrassi
c0b74c2a75 Merge pull request #24 from Nexxa/release-4.1.3
Release 4.1.3
2017-11-09 10:43:29 +01:00
StefanoMagrassi
80aa06a6a1 version 4.1.3 2017-11-09 10:42:40 +01:00
StefanoMagrassi
771674d948 npm package-lock 2017-11-09 10:42:19 +01:00
Stefano Magrassi
51093d00b8 Merge pull request #23 from bmdelacruz/master
Fix "Ios return path" issue
2017-11-09 10:37:34 +01:00
Bryan Dela Cruz
ee4e96a1da Merge pull request #1 from telember/master
Update Base64ToGallery.m (Remove the logging of the image path)
2017-11-06 18:57:50 +08:00
Kittipong Bunmuang
8590d54633 Update Base64ToGallery.m
- fix rm path log
2017-09-05 23:27:57 +07:00
Bryan Dela Cruz
fa0558ea75 Changed callback invocation to pass image path 2017-08-23 00:13:18 +08:00
StefanoMagrassi
d270bcb1a6 Update README.md 2017-01-05 13:07:43 +01:00
StefanoMagrassi
096fada588 version 4.1.2 2016-12-15 08:54:21 +01:00
StefanoMagrassi
f2d7364e2f dependencies updated 2016-12-15 08:52:39 +01:00
StefanoMagrassi
a4b9af06be Merge pull request #15 from romankisil/master
Fixed iOS Error handling
2016-12-14 20:37:42 +01:00
Romans Kisils
a7167e2271 If permissions were declined the iOS code would still call the success callback, now the error is handled and a fail callback is called 2016-12-13 11:30:14 +00:00
StefanoMagrassi
2f531aaa0b version 4.1.1 2016-05-05 17:52:01 +02:00
StefanoMagrassi
f939db234c documentation - options.prefix 2016-05-05 17:49:46 +02:00
StefanoMagrassi
d48ac59654 version 4.1.0 2016-05-05 17:42:11 +02:00
StefanoMagrassi
73661bfde0 documentation 2016-05-05 17:35:44 +02:00
StefanoMagrassi
31676e30c9 documentation 2016-05-05 17:35:05 +02:00
StefanoMagrassi
691bd3fa40 Merge pull request #7 from bastian-meier/iosReturnPath
Ios return path
2016-05-05 17:23:35 +02:00
Bastian Meier
2cd9da795d adding to camera roll works now 2016-05-02 12:40:49 +02:00
Bastian Meier
6c09ce9084 test3 2016-05-02 12:35:48 +02:00
Bastian Meier
35bb949c91 self.imagePath is not needed anymore 2016-05-02 12:35:02 +02:00
Bastian Meier
9f9f4d0e1b test2 2016-05-02 12:34:27 +02:00
Bastian Meier
e53cf1eca4 test 2016-05-02 12:28:01 +02:00
Bastian Meier
225bd5bfc0 typo 2016-05-02 12:00:00 +02:00
Bastian Meier
faf76f2315 undeclared selector error 2016-04-20 16:52:59 +02:00
Bastian Meier
01760d5621 test16 2016-04-18 15:00:43 +02:00
Bastian Meier
d064aea90a test15 2016-04-18 14:51:25 +02:00
Bastian Meier
ff9f8edbea test14 2016-04-18 14:45:24 +02:00
Bastian Meier
b4206a4045 test13 2016-04-18 14:32:07 +02:00
Bastian Meier
c560d6ef1a test12 2016-04-18 14:20:18 +02:00
Bastian Meier
8447803226 test11 2016-04-18 14:16:02 +02:00
Bastian Meier
2fec5c863b test10 2016-04-18 14:07:01 +02:00
Bastian Meier
569fbb77c4 test9 2016-04-18 14:01:22 +02:00
Bastian Meier
ae56b05219 test8 2016-04-18 13:00:05 +02:00
Bastian Meier
80edab88e9 test7 2016-04-18 12:55:47 +02:00
Bastian Meier
39b835717c test6 2016-04-18 12:48:04 +02:00
Bastian Meier
4b40b56677 test5 2016-04-18 12:40:34 +02:00
Bastian Meier
e420a09a81 test4 2016-04-18 12:34:14 +02:00
Bastian Meier
e2695a6af6 test3 2016-04-18 12:26:47 +02:00
Bastian Meier
720458fbbc test2 2016-04-18 12:17:34 +02:00
Bastian Meier
123f36b94a test 2016-04-18 12:11:40 +02:00
Bastian Meier
e687171a32 typos 2016-04-18 11:43:24 +02:00
Bastian Meier
6b39e70581 property imagePath added 2016-04-18 11:39:40 +02:00
Bastian Meier
60aee7b9fd return image path 2016-04-18 11:27:33 +02:00
6 changed files with 1284 additions and 52 deletions

View File

@@ -1,4 +1,4 @@
# Cordova base64ToGallery Plugin
# :warning: DISCONTINUED - Cordova base64ToGallery Plugin
This plugin (based on [devgeeks/Canvas2ImagePlugin](http://github.com/devgeeks/Canvas2ImagePlugin)) allows you to save base64 data as a png image into the device (iOS Photo Library, Android Gallery or WindowsPhone 8 Photo Album).
The plugin is a kind of fork of the [solderzzc/Base64ImageSaverPlugin](https://github.com/solderzzc/Base64ImageSaverPlugin) but with a cleaner history (a.k.a: no tags from Canvas2ImagePlugin repo) and a newer iOS implementation.
@@ -18,27 +18,29 @@ So, cordova-base64-to-gallery plugin **from version 3.0.0** has changed the iOS
If you need to support cordova-ios < 3.8.0 please refer to [cordova-base64-to-gallery@2.0.2](https://github.com/Nexxa/cordova-base64-to-gallery/tree/2.0.2). There is also an "**old**" branch that might have some updates in the future (Android/WP8 fixes or something like that).
## Usage
Call the `cordova.base64ToGallery()` method using success and error callbacks and the passing the image's base64 string (`options` is optional):
Call the `cordova.base64ToGallery()` method with image's base64 string, success and error callbacks (`options` is optional):
### Methods
#### `cordova.base64ToGallery(data, [options, success, fail])`
Param | Type | Default | Description
----------- | ---------- | ----------------- | ------------------
----------- | ---------- | ----------------- | -----------------------------------------
**data** | *string* | | base64 string
**options** | *object* | \*see below | options
**success** | *function* | **console.log** | success callback
**fail** | *function* | **console.error** | fail callback
**success** | *function* | **console.log** | success callback (file path as parameter)
**fail** | *function* | **console.error** | fail callback (error as parameter)
#### Available options *
##### `prefix`
Saved file name prefix. Only works in Android and WP8.
Saved file name prefix.
**Default**: "img_"
##### `mediaScanner`
Android Media Scanner after file creation enabled or not. Only works in Android.
On Android runs Media Scanner after file creation.
On iOS if true the file will be added to camera roll, otherwise will be saved to a library folder.
**Default**: true
@@ -54,8 +56,8 @@ function onDeviceReady() {
mediaScanner: true
},
function(msg) {
console.log(msg);
function(path) {
console.log(path);
},
function(err) {
@@ -69,3 +71,4 @@ function onDeviceReady() {
- [Tommy-Carlos Williams](http://github.com/devgeeks)
- [Simba Zhang](http://github.com/solderzzc)
- [StefanoMagrassi](http://github.com/StefanoMagrassi)
- [Bastian Meier](https://github.com/bastian-meier)

1196
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,20 +1,21 @@
{
"name": "cordova-base64-to-gallery",
"version": "4.0.0",
"name": "@goiarlabs/cordova-base64-to-gallery",
"version": "6.0.0-falopa",
"description": "Cordova plugin to save base64 data as a png image into the device",
"license": "MIT",
"scripts": {
"bump": "node ./scripts/bump_version",
"lint": "eslint www/base64ToGallery.js",
"test": "npm run lint",
"postversion": "npm run bump",
"prepublish": "npm test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Nexxa/cordova-base64-to-gallery.git"
"url": "git+https://github.com/@goiarlabs/cordova-base64-to-gallery.git"
},
"bugs": {
"url": "https://github.com/Nexxa/cordova-base64-to-gallery/issues"
"url": "https://github.com/@goiarlabs/cordova-base64-to-gallery/issues"
},
"engines": [
{
@@ -25,7 +26,7 @@
}
],
"cordova": {
"id": "cordova-base64-to-gallery",
"id": "@goiarlabs/cordova-base64-to-gallery",
"platforms": [
"ios",
"android",
@@ -56,7 +57,7 @@
}
],
"devDependencies": {
"eslint": "1.10.3",
"nodemsg": "1.0.0"
"eslint": "3.12.2",
"nodemsg": "1.1.0"
}
}

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns:android="http://schemas.android.com/apk/res/android" xmlns="http://www.phonegap.com/ns/plugins/1.0" id="cordova-base64-to-gallery" version="4.0.0">
<plugin xmlns:android="http://schemas.android.com/apk/res/android" xmlns="http://www.phonegap.com/ns/plugins/1.0" id="cordova-base64-to-gallery" version="4.1.3">
<engines>
<engine name="cordova-ios" version=">=3.8.0" />

View File

@@ -89,22 +89,10 @@ public class Base64ToGallery extends CordovaPlugin {
int check = deviceVersion.compareTo("2.3.3");
File folder;
File folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
/*
* File path = Environment.getExternalStoragePublicDirectory(
* Environment.DIRECTORY_PICTURES ); //this throws error in Android
* 2.2
*/
if (check >= 1) {
folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
if (!folder.exists()) {
folder.mkdirs();
}
} else {
folder = Environment.getExternalStorageDirectory();
if (!folder.exists()) {
folder.mkdirs();
}
File imageFile = new File(folder, prefix + date + ".png");

View File

@@ -1,3 +1,4 @@
//
// Base64ToGallery.m
// Base64ToGallery PhoneGap/Cordova plugin
@@ -20,39 +21,82 @@
self.callbackId = command.callbackId;
self.result = nil;
NSString* base64String = [command.arguments objectAtIndex:0];
NSString *base64String = [command.arguments objectAtIndex:0];
NSString *prefix = [command.arguments objectAtIndex:1];
bool cameraRoll = [[command.arguments objectAtIndex:2] boolValue];
if (base64String != nil && [base64String length] > 0) {
NSData *imageData = [[[NSData alloc] initWithBase64EncodedString:base64String options:0] autorelease];
UIImage *image = [[[UIImage alloc] initWithData:imageData] autorelease];
NSData* imageData = [[[NSData alloc] initWithBase64EncodedString:base64String options:0] autorelease];
UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease];
// converts the UIImage to NSData
NSData *pngImageData = UIImagePNGRepresentation(image);
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
// image extension
NSString *imageExtension = @".png";
// get Timestamp
double currentTime = CACurrentMediaTime();
// set fileName
NSString *timeString = [NSString stringWithFormat:@"%f", currentTime];
timeString = [timeString stringByReplacingOccurrencesOfString:@"." withString:@""];
NSString *fileName = [prefix stringByAppendingString: timeString];
fileName = [fileName stringByAppendingString: imageExtension];
NSString *libPath = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0];
NSString *libPathNoSync = [libPath stringByAppendingPathComponent:@"NoCloud"];
NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager
// Create the directory if necessary.
[fileManager createDirectoryAtPath:libPathNoSync withIntermediateDirectories:YES attributes:nil error:nil];
NSString *imagePath = [libPathNoSync stringByAppendingPathComponent:fileName];
// writeToFile
bool success = [fileManager createFileAtPath:imagePath contents:pngImageData attributes:nil];
if(success){
// write to documents folder was successfull
if(cameraRoll){
// add the image to camera roll
UIImage * savedImage = [UIImage imageWithContentsOfFile:imagePath];
UIImageWriteToSavedPhotosAlbum(savedImage, self,
@selector(thisImage:hasBeenSavedInPhotoAlbumWithError:onImagePath:),
(void *) CFBridgingRetain(imagePath));
} else {
// send back the image path of the saved image
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:imagePath];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
}
}else{
imagePath = [imagePath stringByAppendingString: @" - error writing image to documents folder"];
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:imagePath];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
}
} else {
self.result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
[self.commandDelegate sendPluginResult:self.result callbackId:self.callbackId];
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no valid base64 image data was passed"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
}
}];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
// With errors
if (error != NULL) {
NSLog(@"ERROR: %@", error);
self.result = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString:error.description];
// No errors
-(void)thisImage:(UIImage *)image hasBeenSavedInPhotoAlbumWithError:(NSError *)error onImagePath:(void*)bridgedImagePath{
if (error) {
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Error saving Image to Gallery, check Permissions"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
} else {
// retrieve bridged image path and release it to get the image path
NSString *imagePath = (NSString *) CFBridgingRelease(bridgedImagePath);
self.result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
// send the image path back to the js callback
CDVPluginResult * pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:imagePath];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
}
[self.commandDelegate sendPluginResult:self.result callbackId:self.callbackId];
}
@end