Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var enumsModule = require("ui/enums");
var cameraModule = require("camera");
var fs = require('file-system');
var bghttp = require("nativescript-background-http");
exports.takephoto = function(args) {
cameraModule.takePicture({width: 800, height: 800, keepAspectRatio: true}).then(function(picture) {
var savepath = fs.knownFolders.currentApp().path + "/saved_images";
var filename = 'img_' + new Date().getTime() + '.jpg';
var filepath = fs.path.join(savepath, filename);
var picsaved = picture.saveToFile(filepath, enumsModule.ImageFormat.jpeg);
if(picsaved) {
console.log("Saving");
var session = bghttp.session("image-upload");
var request = {
url: config.apiUrl,
method: "POST",
headers: {
"Content-Type": "application/octet-stream",
"File-Name": filename
},
description: "{ 'uploading': '" + filename + "' }"
};
var task = session.uploadFile("file://" + filepath, request);
task.on("progress", logEvent);
task.on("error", logEvent);
task.on("complete", logEvent);
function logEvent(e) {
console.log(e.eventName);
}
} else {
console.log("Failed To Save");
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.