mirror of
https://github.com/apache/cordova-plugin-camera.git
synced 2025-03-16 22:11:02 +08:00
CB-2442 CB-2419 Use Windows.Storage.ApplicationData.current.localFolder, instead of writing to app package.
This commit is contained in:
parent
ccd59e66ba
commit
2437c40fe7
@ -22,6 +22,7 @@
|
|||||||
/*global Windows:true, URL:true */
|
/*global Windows:true, URL:true */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var cordova = require('cordova'),
|
var cordova = require('cordova'),
|
||||||
Camera = require('./Camera'),
|
Camera = require('./Camera'),
|
||||||
FileEntry = require('org.apache.cordova.file.FileEntry'),
|
FileEntry = require('org.apache.cordova.file.FileEntry'),
|
||||||
@ -90,16 +91,23 @@ module.exports = {
|
|||||||
// The resized file ready for upload
|
// The resized file ready for upload
|
||||||
var _blob = canvas.msToBlob();
|
var _blob = canvas.msToBlob();
|
||||||
var _stream = _blob.msDetachStream();
|
var _stream = _blob.msDetachStream();
|
||||||
Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {
|
|
||||||
|
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
|
||||||
storageFolder.createFileAsync(tempPhotoFileName, Windows.Storage.CreationCollisionOption.generateUniqueName).done(function (file) {
|
storageFolder.createFileAsync(tempPhotoFileName, Windows.Storage.CreationCollisionOption.generateUniqueName).done(function (file) {
|
||||||
file.openAsync(Windows.Storage.FileAccessMode.readWrite).done(function (fileStream) {
|
file.openAsync(Windows.Storage.FileAccessMode.readWrite).done(function (fileStream) {
|
||||||
Windows.Storage.Streams.RandomAccessStream.copyAndCloseAsync(_stream, fileStream).done(function () {
|
Windows.Storage.Streams.RandomAccessStream.copyAndCloseAsync(_stream, fileStream).done(function () {
|
||||||
var _imageUrl = URL.createObjectURL(file);
|
var _imageUrl = URL.createObjectURL(file);
|
||||||
successCallback(_imageUrl);
|
successCallback(_imageUrl);
|
||||||
}, function () { errorCallback("Resize picture error."); });
|
}, function () {
|
||||||
}, function () { errorCallback("Resize picture error."); });
|
errorCallback("Resize picture error.");
|
||||||
}, function () { errorCallback("Resize picture error."); });
|
|
||||||
});
|
});
|
||||||
|
}, function () {
|
||||||
|
errorCallback("Resize picture error.");
|
||||||
|
});
|
||||||
|
}, function () {
|
||||||
|
errorCallback("Resize picture error.");
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -112,7 +120,7 @@ module.exports = {
|
|||||||
fileEntry.file(successCB, failCB);
|
fileEntry.file(successCB, failCB);
|
||||||
};
|
};
|
||||||
|
|
||||||
Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {
|
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
|
||||||
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
|
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
|
||||||
success(new FileEntry(storageFile.name, storageFile.path));
|
success(new FileEntry(storageFile.name, storageFile.path));
|
||||||
}, function () {
|
}, function () {
|
||||||
@ -120,7 +128,6 @@ module.exports = {
|
|||||||
}, function () {
|
}, function () {
|
||||||
errorCallback("Folder not access.");
|
errorCallback("Folder not access.");
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -165,15 +172,15 @@ module.exports = {
|
|||||||
fileEntry.file(successCB, failCB);
|
fileEntry.file(successCB, failCB);
|
||||||
};
|
};
|
||||||
|
|
||||||
Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {
|
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
|
||||||
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
|
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
|
||||||
success(new FileEntry(storageFile.name, storageFile.path));
|
success(new FileEntry(storageFile.name, "ms-appdata:///local/" + storageFile.name));
|
||||||
}, function () {
|
}, function () {
|
||||||
fail(FileError.INVALID_MODIFICATION_ERR);
|
fail(FileError.INVALID_MODIFICATION_ERR);
|
||||||
}, function () {
|
}, function () {
|
||||||
errorCallback("Folder not access.");
|
errorCallback("Folder not access.");
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -182,9 +189,11 @@ module.exports = {
|
|||||||
fileOpenPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary;
|
fileOpenPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.picturesLibrary;
|
||||||
if (mediaType == Camera.MediaType.PICTURE) {
|
if (mediaType == Camera.MediaType.PICTURE) {
|
||||||
fileOpenPicker.fileTypeFilter.replaceAll([".png", ".jpg", ".jpeg"]);
|
fileOpenPicker.fileTypeFilter.replaceAll([".png", ".jpg", ".jpeg"]);
|
||||||
} else if (mediaType == Camera.MediaType.VIDEO) {
|
}
|
||||||
|
else if (mediaType == Camera.MediaType.VIDEO) {
|
||||||
fileOpenPicker.fileTypeFilter.replaceAll([".avi", ".flv", ".asx", ".asf", ".mov", ".mp4", ".mpg", ".rm", ".srt", ".swf", ".wmv", ".vob"]);
|
fileOpenPicker.fileTypeFilter.replaceAll([".avi", ".flv", ".asx", ".asf", ".mov", ".mp4", ".mpg", ".rm", ".srt", ".swf", ".wmv", ".vob"]);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
fileOpenPicker.fileTypeFilter.replaceAll(["*"]);
|
fileOpenPicker.fileTypeFilter.replaceAll(["*"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,17 +202,17 @@ module.exports = {
|
|||||||
if (destinationType == Camera.DestinationType.FILE_URI) {
|
if (destinationType == Camera.DestinationType.FILE_URI) {
|
||||||
if (targetHeight > 0 && targetWidth > 0) {
|
if (targetHeight > 0 && targetWidth > 0) {
|
||||||
resizeImage(file);
|
resizeImage(file);
|
||||||
} else {
|
}
|
||||||
Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {
|
else {
|
||||||
|
|
||||||
|
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
|
||||||
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
|
file.copyAsync(storageFolder, file.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
|
||||||
var _imageUrl = URL.createObjectURL(storageFile);
|
successCallback(URL.createObjectURL(storageFile));
|
||||||
successCallback(_imageUrl);
|
|
||||||
}, function () {
|
}, function () {
|
||||||
fail(FileError.INVALID_MODIFICATION_ERR);
|
fail(FileError.INVALID_MODIFICATION_ERR);
|
||||||
}, function () {
|
}, function () {
|
||||||
errorCallback("Folder not access.");
|
errorCallback("Folder not access.");
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,18 +249,24 @@ module.exports = {
|
|||||||
} else {
|
} else {
|
||||||
cameraCaptureUI.photoSettings.format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.jpeg;
|
cameraCaptureUI.photoSettings.format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.jpeg;
|
||||||
}
|
}
|
||||||
|
|
||||||
// decide which max pixels should be supported by targetWidth or targetHeight.
|
// decide which max pixels should be supported by targetWidth or targetHeight.
|
||||||
if (targetWidth >= 1280 || targetHeight >= 960) {
|
if (targetWidth >= 1280 || targetHeight >= 960) {
|
||||||
cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.large3M;
|
cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.large3M;
|
||||||
} else if (targetWidth >= 1024 || targetHeight >= 768) {
|
}
|
||||||
|
else if (targetWidth >= 1024 || targetHeight >= 768) {
|
||||||
cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.mediumXga;
|
cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.mediumXga;
|
||||||
} else if (targetWidth >= 800 || targetHeight >= 600) {
|
}
|
||||||
|
else if (targetWidth >= 800 || targetHeight >= 600) {
|
||||||
cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.mediumXga;
|
cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.mediumXga;
|
||||||
} else if (targetWidth >= 640 || targetHeight >= 480) {
|
}
|
||||||
|
else if (targetWidth >= 640 || targetHeight >= 480) {
|
||||||
cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.smallVga;
|
cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.smallVga;
|
||||||
} else if (targetWidth >= 320 || targetHeight >= 240) {
|
}
|
||||||
|
else if (targetWidth >= 320 || targetHeight >= 240) {
|
||||||
cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.verySmallQvga;
|
cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.verySmallQvga;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.highestAvailable;
|
cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.highestAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,16 +278,15 @@ module.exports = {
|
|||||||
if (targetHeight > 0 && targetWidth > 0) {
|
if (targetHeight > 0 && targetWidth > 0) {
|
||||||
resizeImage(picture);
|
resizeImage(picture);
|
||||||
} else {
|
} else {
|
||||||
Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {
|
|
||||||
|
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
|
||||||
picture.copyAsync(storageFolder, picture.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
|
picture.copyAsync(storageFolder, picture.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
|
||||||
var _imageUrl = URL.createObjectURL(storageFile);
|
successCallback("ms-appdata:///local/" + storageFile.name);
|
||||||
successCallback(_imageUrl);
|
|
||||||
}, function () {
|
}, function () {
|
||||||
fail(FileError.INVALID_MODIFICATION_ERR);
|
fail(FileError.INVALID_MODIFICATION_ERR);
|
||||||
}, function () {
|
}, function () {
|
||||||
errorCallback("Folder not access.");
|
errorCallback("Folder not access.");
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (targetHeight > 0 && targetWidth > 0) {
|
if (targetHeight > 0 && targetWidth > 0) {
|
||||||
@ -306,16 +320,15 @@ module.exports = {
|
|||||||
if (targetHeight > 0 && targetWidth > 0) {
|
if (targetHeight > 0 && targetWidth > 0) {
|
||||||
resizeImage(picture);
|
resizeImage(picture);
|
||||||
} else {
|
} else {
|
||||||
Windows.Storage.StorageFolder.getFolderFromPathAsync(packageId.path).done(function (storageFolder) {
|
|
||||||
|
var storageFolder = Windows.Storage.ApplicationData.current.localFolder;
|
||||||
picture.copyAsync(storageFolder, picture.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
|
picture.copyAsync(storageFolder, picture.name, Windows.Storage.NameCollisionOption.replaceExisting).then(function (storageFile) {
|
||||||
var _imageUrl = URL.createObjectURL(storageFile);
|
successCallback("ms-appdata:///local/" + storageFile.name);
|
||||||
successCallback(_imageUrl);
|
|
||||||
}, function () {
|
}, function () {
|
||||||
fail(FileError.INVALID_MODIFICATION_ERR);
|
fail(FileError.INVALID_MODIFICATION_ERR);
|
||||||
}, function () {
|
}, function () {
|
||||||
errorCallback("Folder not access.");
|
errorCallback("Folder not access.");
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (targetHeight > 0 && targetWidth > 0) {
|
if (targetHeight > 0 && targetWidth > 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user