Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Contributor
Posts: 5
Registered: ‎11-15-2013
My Device: developer
My Carrier: developer
Accepted Solution

Save Photo on Gallery

Hellow forum.

 

I have an issue with one app that was rejected during vetting process.

 

There is a function in which you can put together a picture + a character and save the photo on the gallery. Everythings works properly but when you try to recover the picture from the gallery you get an error.

 

How can help me to understand why the images can`t be open later?

 

Thank you.

 

/*functions for saving the image*/
function savePhoto(){
var canvas = document.getElementById("fotoTomadaPizarra"); /*the canvas*/
var dataURL = canvas.toDataURL('image/jpeg');
try{
dataURL = dataURL.replace('data:image/jpeg;base64,', '');
saveFile(dataURL, '/accounts/1000/shared/camera/cc'+Date.now()+'.jpg');
}catch(e){
alert(e);
}
}

function saveFile(savedata, openat, picker, ext) {
blackberry.io.sandbox = false;
if (ext == null) ext = '';
if (picker != 'picker') {
window.webkitRequestFileSystem(window.TEMPORARY, 5 * 1024 * 1024, function (fileSystem) {
fileSystem.root.getFile(openat, {create : true}, function (fileEntry) {
fileEntry.createWriter(function (fileWriter) {
fileWriter.onwriteend = function () {blackberry.ui.toast.show('Guardado!');};
fileWriter.onerror = function (fileError) {blackberry.ui.toast.show(fileError);};

try{
var blob = new Blob([savedata], {type : 'image/jpeg'});
fileWriter.write(blob);
}catch(e){alert(e)}
$.mobile.loading('hide');
document.getElementById("loadingDiv").style.display = "none";
});
},errorHandler);
});
}
else {
blackberry.invoke.card.invokeFilePicker({
mode: blackberry.invoke.card.FILEPICKER_MODE_SAVER,
directory: [openat],
viewMode: blackberry.invoke.card.FILEPICKER_VIEWER_MODE_GRID,
sortBy: blackberry.invoke.card.FILEPICKER_SORT_BY_NAME,
sortOrder: blackberry.invoke.card.FILEPICKER_SORT_ORDER_ASCENDING
}, function (path) {
window.webkitRequestFileSystem(window.TEMPORARY, 5 * 1024 * 1024, function (fileSystem) {
fileSystem.root.getFile(path+'.jpg', {create : true}, function (fileEntry) {
fileEntry.createWriter(function (fileWriter) {
var blob = new Blob([savedata], {type : 'image/jpeg'});
fileWriter.write(blob);
fileWriter.onwriteend = function () {blackberry.ui.toast.show('Guardado!');};
fileWriter.onerror = function (fileError) {blackberry.ui.toast.show(fileError);};
$.mobile.loading('hide');
document.getElementById("loadingDiv").style.display = "none";
});
});
});
});
}
}

BlackBerry Development Advisor
Posts: 760
Registered: ‎10-01-2009
My Device: All
My Carrier: N/A

Re: Save Photo on Gallery

What exactly happens when you try to load the image after it's been saved?

 

If you browse the photos (after saving) do you see the photo there? Do you see the thumbnail?

 

My guess is that the image is not actually saving properlly. Have you tried following this sample app: https://github.com/blackberry/BB10-WebWorks-Samples/tree/master/canvasToFilesystem

New Contributor
Posts: 5
Registered: ‎11-15-2013
My Device: developer
My Carrier: developer

Re: Save Photo on Gallery


chadtatro wrote:

What exactly happens when you try to load the image after it's been saved?

 

If you browse the photos (after saving) do you see the photo there? Do you see the thumbnail?

 

My guess is that the image is not actually saving properlly. Have you tried following this sample app: https://github.com/blackberry/BB10-WebWorks-Samples/tree/master/canvasToFilesystem



i can see the photo on browser, but can`t open it and can`t see the thumbnail.

 

i try that sample on my smartphone with same result, not thumbnail, can't open image.

BlackBerry Development Advisor
Posts: 760
Registered: ‎10-01-2009
My Device: All
My Carrier: N/A

Re: Save Photo on Gallery

The image isn't being saved right then, it's not saved as a valid image by the sounds of it.

 

 

I've definitely gotten that sample to work without problems. I use it in my own projects as well.

New Contributor
Posts: 5
Registered: ‎11-15-2013
My Device: developer
My Carrier: developer

Re: Save Photo on Gallery

sorry, but it doesn't work at less on my devices.

 

i remake my code using it and it doesn't work too.

 

any idea about it on my code?

 

thank u bery much

New Contributor
Posts: 5
Registered: ‎11-15-2013
My Device: developer
My Carrier: developer

Re: Save Photo on Gallery

hellow again.

 

using try catch on your sample. it throws exception "TypeError: 'undefined' is not a constructor (evaluating 'new j')"

 

 


 

try{
canvas.toBlob(
function (blob) {
fileWriter.write(blob);
},
'image/png'
);
}catch(e){alert(e)}

 


 

New Contributor
Posts: 5
Registered: ‎11-15-2013
My Device: developer
My Carrier: developer

Re: Save Photo on Gallery

i got it.

 

I do not know exactly where the problem was. but this has been solved using another library.

 

https://github.com/blueimp/JavaScript-Canvas-to-Blob/blob/master/js/canvas-to-blob.js

 

thank u for your help and time.

BlackBerry Development Advisor
Posts: 760
Registered: ‎10-01-2009
My Device: All
My Carrier: N/A

Re: Save Photo on Gallery

Awesome, glad you were able to get it working. Smiley Happy