public onUploadDocTap() {
//openFilePicker().then((res) => {
if (Device.sdkVersion >= ’30’) {
let imageOptionsDocumentPicker: FilePickerOptionsDocumentPicker = {
extensions: [
‘jpg’,
‘jpeg’,
‘png’,
‘pdf’
],
multipleSelection: true,
permissions: {
write: true,
read: true,
recursive: true,
persistable: true,
}
}
openFilePicker(imageOptionsDocumentPicker).then((data) => {
const retval: Array = [];
data.files.forEach((file) => {
let savedFile = File.fromPath(file, true);
const document: SupportingDocument = {
url: savedFile.path,
fileSize: savedFile.size
};
retval.push(document);

console.log(savedFile.path);
this.filePath = savedFile.path;
this.Uploaddoc(savedFile.path);

})
})
}
else{

this.onItemTapnew();

}

// })
}

public Uploaddoc(filename) {
console.log(“Attachment portion started”);
// openFilePicker().then((res) => {

// this.filePath = res.files[0];

//==========================
// file path and url
//var file = res.files[0];
//var file = “content://com.android.providers.media.documents/document/image%3A1000056048.jpg”;
var file = filename;
console.log(file);
var url = ApplicationSettings.getString(“hrmsurl”);
var name = file.substr(file.lastIndexOf(“/”) + 1);
console.log(‘url :- ‘ + url + ‘ name ‘ + name);
// upload configuration

this.input.UploadDocument = name;
var bghttp = require(“@nativescript/background-http”);
var session = bghttp.session(“image-upload”);
//var session = bghttp.session(“file-upload”);
console.log(“url :- ” + ApplicationSettings.getString(“hrmsurl”) + “/MobileSetup/MobileUpload”);
var request = {

url: ApplicationSettings.getString(“hrmsurl”) + “/MobileSetup/MobileUpload”,
method: “POST”,
headers: {
“Content-Type”: “application/octet-stream”,
“uploadtype”: “leave”,
“apikey”: ApplicationSettings.getString(“APIKey”),
“apicode”: ApplicationSettings.getString(“APICode”),
},

description: “Uploading ” + name
};

var params = [

{ name: “test”, value: “value” },
{ name: “fileToUpload”, filename: file, mimeType: “image/jpeg” }

];
var task = session.multipartUpload(params, request);

task.on(“responded”, responded);

var myimage=””;
function responded(e) {

console.log(“data: ” + e.data);
var res = JSON.parse(e.data);
//console.log(“image : ” + res[‘filename’]);

myimage = res[‘filename’];

this.imagefile = myimage;

// myimage.slice(0, -1);

console.log(“image: ” + this.imagefile);
ApplicationSettings.setString(“uploadeddoc”, this.imagefile);
}

return task;

// })
}

By admin