Created
June 30, 2016 17:52
-
-
Save ChrisFlannagan/e9e32428935076419f24aec6a30a7381 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
how to compress images before upload in NS?