Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Ios return path #22

Closed
maxborgatti opened this issue Aug 29, 2017 · 7 comments · Fixed by #23
Closed

Ios return path #22

maxborgatti opened this issue Aug 29, 2017 · 7 comments · Fixed by #23

Comments

@maxborgatti
Copy link

I'm getting "Image Saved to Gallery" as res, only on iOS. On android works fine and gives me back the path.

Is it a bug or am i missing something? Here is my code (i get imageData from cameraPreview plugin):

this.base64ToGallery.base64ToGallery(imageData[0]).then((res) => { console.log('Saved image to gallery ', res) }, err => console.log('Error saving image to gallery ', err) );

@asadwaheed1
Copy link

Same here me too

@asadwaheed1
Copy link

@maxborgatti did you find any solution

@maxborgatti
Copy link
Author

unfortunately not: i had to abandon this plugin

@asadwaheed1
Copy link

then how you save file and get its path back in ios

@maxborgatti
Copy link
Author

i did use base64. but if you want you can use file plugin (http://ionicframework.com/docs/native/file/) to write down the base64

convert base64 to blob and then write down

@asadwaheed1
Copy link

Thanks but i am currently using this base64 to blob using file plugin but it is writing image with zero bytes blank. here's my code

`
/**

  • Create a Image file according to its database64 content only.

  • @param folderpath {String} The folder where the file will be created

  • @param filename {String} The name of the file that will be created

  • @param content {Base64 String} Important : The content can't contain the following string (data:image/png[or any other format];base64,). Only the base64 string is expected.
    */
    savebase64AsImageFile(folderpath, filename, content, contentType) {
    // Convert the base64 string in a Blob
    return new Promise((resolve, reject) => {
    var DataBlob = this.b64toBlob(content, contentType, 512);

    console.log("Starting to write the file :3");
    this.file.resolveDirectoryUrl(folderpath).then(dir => {
    console.log("Access to the directory granted succesfully");
    dir.getFile(filename, {create: true}, function (file) {
    console.log("File created succesfully.");
    file.createWriter(function (fileWriter) {
    console.log("Writing content to file");
    fileWriter.write(DataBlob);
    resolve(true)
    }, function () {
    alert('Unable to save file in path ' + folderpath);
    reject(false)
    });
    });
    });
    });
    }

/**

var byteCharacters = atob(b64Data);
var byteArrays = [];

for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
  var slice = byteCharacters.slice(offset, offset + sliceSize);

  var byteNumbers = new Array(slice.length);
  for (var i = 0; i < slice.length; i++) {
    byteNumbers[i] = slice.charCodeAt(i);
  }

  var byteArray = new Uint8Array(byteNumbers);

  byteArrays.push(byteArray);
}

var blob = new Blob(byteArrays, {type: contentType});
return blob;

}

// If your base64 string contains "data:image/png;base64,"" at the beginning, keep reading.
var myBase64 = this.img;
// Split the base64 string in data and contentType
var block = myBase64.split(";");
// Get the content type
var dataType = block[0].split(":")[1];// In this case "image/png"
// get the real base64 content of the file
var realData = block[1].split(",")[1];// In this case "iVBORw0KGg...."

// The path where the file will be created
var folderpath = this.file.documentsDirectory;
// The name of your file, note that you need to know if is .png,.jpeg etc
var filename = "myimage.png";`

can you please tell me what am i doing wrong?

@bmdelacruz
Copy link
Contributor

I hope this is not yet late for you guys, but I silently created a fork of this repo to fix this issue a long time ago. I did not create a pull request because it says that this repo is already discontinued. Here's the link to the commit where I made changes to the source for ios.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants