*/
writeFile: function SystemIO_writeFile(fileHandle, fileContent, onSuccess, onError, contentEncoding) {
onError = onError || function () {};
-
fileHandle.openStream('w', function (fileStream) {
- if (contentEncoding === 'base64') {
- fileStream.writeBase64(fileContent);
- } else {
- fileStream.write(fileContent);
+ try {
+ if (contentEncoding === 'base64') {
+ fileStream.writeBase64(fileContent);
+ } else {
+ fileStream.write(fileContent);
+ }
+ fileStream.close();
+ } catch(e) {
+ onError(fileHandle);
}
-
- fileStream.close();
-
- // launch onSuccess callback
if (typeof onSuccess === 'function') {
onSuccess(fileHandle);
}
* @param {string} file content
* @param {string} file encoding
*/
- saveFileContent: function SystemIO_saveFileContent(filePath, fileContent, onSaveSuccess, fileEncoding) {
+ saveFileContent: function SystemIO_saveFileContent(filePath, fileContent, onSaveSuccess, onSaveFailure, fileEncoding) {
var pathData = this.getPathData(filePath),
self = this,
fileHandle;
fileHandle = self.createFile(dir, pathData.fileName);
if (fileHandle !== false) {
// save data into this file
- self.writeFile(fileHandle, fileContent, onSaveSuccess, false, fileEncoding);
+ self.writeFile(fileHandle, fileContent, onSaveSuccess, onSaveFailure, fileEncoding);
+ } else {
+ onSaveFailure();
}
}
// open directory
- this.openDir(pathData.dirName, onOpenDirSuccess);
+ this.openDir(pathData.dirName, onOpenDirSuccess, onSaveFailure);
},
/**
};
SelfCamera.prototype.saveCanvas = function saveCanvas(canvas, fileName) {
- var data, self = this, onSuccess = function (fileHandle) {
- this.setLoadDirectory(this.getFileDirectoryURI(fileHandle));
- tizen.content.scanFile(fileName, function () {
- setTimeout(function(){ self.loadThumbnail(true, true); }, 200);
- }, function () {
- console.error('scanFile: file not found');
- self.loadThumbnail(true, false);
- });
- }.bind(this);
+ var data,
+ self = this,
+ onSuccess = function (fileHandle) {
+ this.setLoadDirectory(this.getFileDirectoryURI(fileHandle));
+ tizen.content.scanFile(
+ fileName,
+ function () {
+ setTimeout(function(){ self.loadThumbnail(true, true); }, 200);
+ },
+ function () {
+ console.error('scanFile: file not found');
+ self.loadThumbnail(true, false);
+ });
+ }.bind(this),
+ onFailure = function (e) {
+ alert("Failed to take photo!");
+ };
try {
data = canvas.toDataURL().replace('data:image/png;base64,', '').replace('data:,', '');
try {
this.systemIO.deleteNode(fileName, function () {
try {
- this.systemIO.saveFileContent(fileName, data, onSuccess, 'base64');
+ this.systemIO.saveFileContent(fileName, data, onSuccess, onFailure, 'base64');
} catch (e) {
console.error('saveDataToFile error: ' + e.message);
}