Download a CSV?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Download a CSV?
I am trying to create a list of parts by tapping on a model and then download that list as a CSV. It works great on preview mode but does not work in Vuforia View.
I have tried:
$scope.CreateCSV=function(){
var rows= $scope.PartTableList;
var csvContent =[];// "data:text/csv;charset=utf-8;";
// Add headers
const headers = Object.keys(rows[0]).join(",");
csvContent += headers + "\r\n";
// Add data rows
rows.forEach(item => {
const values = Object.values(item).join(",");
csvContent += values + "\r\n";
});
var encodedUri = encodeURI(csvContent);
window.location.assign(encodedUri);
}
and that works in preview but not in Vuforia View.
I have also tried another method:
$scope.CreateCSV=function(){
var rows= $scope.PartTableList;
var csvContent =[];// "data:text/csv;charset=utf-8;";
// Add headers
const headers = Object.keys(rows[0]).join(",");
csvContent += headers + "\r\n";
// Add data rows
rows.forEach(item => {
const values = Object.values(item).join(",");
csvContent += values + "\r\n";
});
$scope.downloadcsv=function(content, filename, contentType) {
// Create a blob
var blob = new Blob([content], { type: contentType });
var url = URL.createObjectURL(blob);
// Create a link to download it
var pom = document.createElement('a');
pom.href = url;
pom.setAttribute('download', filename);
pom.click();
document.body.removeChild(pom)
}
With the same results.
Is there any way to do this?
- Labels:
-
Best Practices
- Tags:
- download file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi @JR_10569306 ,
I do not think that is allowed in the Vuforia View. So the security concept does not allow to to save data locally or to download.
So what it will work to save the data to Thingworx and then to download form there. Tested and was working on IOS iPad
////////////////////////////////////////////////////////
$scope.app.testTable2TWX=()=>{
console.warn($scope.app.Table)
// that variable contains the Table as array of jsons obj
let csvContent=$scope.app.CreateCSV($scope.app.Table)
console.log(csvContent)
let params={'content':csvContent.toString(),'path':'/CSV/list.csv'}
twx.app.fn.triggerDataService('CADtestFileRep1', 'SaveText', params )
}
//===========================
//=======custom funciton
$scope.app.CreateCSV=function(table){
console.log("called $scope.app.CreateCSV()")
var rows= table;
let csvContent =[];// "data:text/csv;charset=utf-8;";
// Add headers
const headers = Object.keys(rows[0]).join(",");
csvContent += headers +"\n";
// Add data rows
rows.forEach(item => {
const values = Object.values(item).join(",");
csvContent += values+"\n" ;
});
return csvContent;
}
//========================================
So on IOS when I use Hyperlink widget with URL = /Thingworx/FileRepositories/CADtestFileRep1/CSV/list.csv
That is the fileRepository path where I loaded the csv - that allowed to save it on the iOS iPad devices
Here a published , public Vuforia Studio demo project if you want to test . I published on my server. If you need to use in your enviroment you need to create thing from FileRepository template named "CADtestFileRep1" and create there a folder /CSV .Also set the permission for Experience Service according to :
https://support.ptc.com/help/vuforia/studio/en/#page/Studio_Help_Center%2FGrantUserPermissions.html
https://support.ptc.com/help/vuforia/studio/en/#page/Studio_Help_Center%2FAnonymousAccess.html%23
here to test
