Angular filesaver download csv data with # is unable to download - special-characters

I'm new to coding. I'm doing a task to download a csv file from DB.
When I use angular filesaver to download the csv, if the content with #, the word after # will not be displayed. It would be appreciated if anyone can give me some hits to fix this :)
onBtnExportClick(){
let testContent = "SOVEREIGN SURGICAL BLADES STERILE #11"
saveAs('data:text/csv;charset=utf-8,%EF%BB%BF' + testContent , 'TestFile.csv');
}

fixed with this code
var blob = new Blob([r.FileContent], {type: r.FileMIMEType});
saveAs(blob, r.FileName);

Related

how to rename or delete file in local storage using flutter

I am developing an audio player using flutter.
In this project, I am using on_audio_query package to list all audio files from my mobile, then select one to play it.
I want to know, is there anyway to rename a file or delete it?
So the user can select one file and rename it, or select one or multiple files and delete them.
Thanks in advance
Try this example:
Future changeFileNameOnly(File file, String newFileName) {
var path = file.path;
var lastSeparator = path.lastIndexOf(Platform.pathSeparator);
var newPath = path.substring(0, lastSeparator + 1) + newFileName;
return file.rename(newPath);
}
Use permission_handler to get access to manage_external_storage before..
Don't forget to add it in manifest
You can also use the shared storage to get access..
By using i think saf package

Use Google Scripts to Attach PDF to email

I am trying to have google Scripts send a PDF as an attachment to an email. I have a doc template that uses form data that is copied and then filled out. The code works, but the program keeps sending the template as a pdf and not the filled out copy. Can anyone help me with this?
Here is some of my code:
newDoc = autoWriteNewIEPForm(templateDocId, newDocName, fieldArray, NewEntryArray, submitTeacherName);
newDocId = newDoc.getId();
newDocURL = newDoc.getUrl();
var sender = newEntryArray[0][3];
var subSubject = newDocName;
var subEmailBody = "Thank you for submitting this information. This receipt confirms that we have received your information." + "<br><br>";
var file = DriveApp.getFileById(newDocId).getAs(MimeType.PDF);
MailApp.sendEmail(sender, subSubject, "", {cc:emailCC, htmlBody:subEmailBody, attachments:[file], name: newDocName});
Well the last line of your code is correctly attaching the newDoc as an attachment. The first line confuses me a bit; autoWriteNewIEPForm is not a Google scripts function, and I don't know where you're getting it from or if you're using it correctly. My guess is that you're using it incorrectly, or that for some reason it's not editing any of the text in the newDoc, so you have a document that is technically a copy of the template but looks exactly the same.
In the Body class of the Google Scripts DocumentApp you can find a number of methods for editing text in a document's body. I suggest you use one of those instead.

How to read from excel and write into excel in Protractor?

I have integrated with Rally which downloads test cases .Every Test case has its own test data in excel spread sheet form.
I am planning to consolidate all test cases excel data into single excel sheet and read the test data from this consolidated excel as part of data driven testing.
So I would like to know how to read from excel and write into excel in protractor.
Hope i am clear .
Thank you.
You can use one of these node packages.
https://www.npmjs.com/package/xlsx
https://www.npmjs.com/package/edit-xlsx
I think the second one would be ideal for you as you need to edit existing excel files.
I'm using Exceljs to make my test cases data driven.
https://www.npmjs.com/package/exceljs
Code sample for reading from excel:
var Excel = require('exceljs');
var wrkbook = new Excel.Workbook();
wrkbook.xlsx.readFile('Auto.xlsx').then(function() {
var worksheet = wrkbook.getWorksheet('Master');
worksheet.eachRow(function (Row, rowNumber) {
console.log("Row " + rowNumber + " = " + JSON.stringify(Row.values));
});
});

Google Apps Script: Export Dashboard to CSV

I've created a Dashboard similar to the example provided on the Google Apps Script Help Center. It contains controls which filters the spreadsheet that contains the data. I would like to add an option on the dashboard that would allow the users to export the filtered view to a new CSV file or Google Sheets file that would be saved in their Drive however I've no idea how to do this. Any suggestions?
Here's a code snippet from Google tutorial:
function saveAsCSV() {
// Prompts the user for the file name
var fileName = Browser.inputBox("Save CSV file as (e.g. myCSVFile):");
// Check that the file name entered wasn't empty
if (fileName.length !== 0) {
// Add the ".csv" extension to the file name
fileName = fileName + ".csv";
// Convert the range data to CSV format
var csvFile = convertRangeToCsvFile_(fileName);
// Create a file in the Docs List with the given name and the CSV data
DocsList.createFile(fileName, csvFile);
}
else {
Browser.msgBox("Error: Please enter a CSV file name.");
}
}*
View the full tutorial and code here.

Image not showing immediately after uploading in sails.js

In my application ,I have stored uploaded images to folder ./assets/uploads. I am using easyimage and imagemagick for storing the images.
In my application, after uploading the images, it should show the new uploaded image. But it is not displayed even if the page is refreshed. But when i do sails lift , the image is shown.
How to show image immediately after uploading the image? Thanks a lot!
It's a totally normal situation, because of the way Sails works with the assets.
The thing is that upon sails lift the assets are being copied (including directory structure and symlinks) from ./assets folder to ./.tmp/public, which becomes publicly accessible.
So, in order to show your images immediately after upload, you, basically, need to upload them not to ./assets/uploads but to ./.tmp/public/uploads.
The only problem now is that the ./.tmp folder is being rewritten each time your application restarts, and storing uploads in ./tmp/... would make them erased after every sails lift. The solution here would be storing uploads in, for example, ./uploads and having a symlink ./assets/uploads pointing to ../uploads.
Though this question is pretty old but I would like to add a solution which I just implemented.
Today I spend almost 4 hours trying all those solutions out there. But none helped. I hope this solution will save someone else's time.
WHY images are not available immediately after uploading to any custom directory?
Because according to the default Sails setup, you can not access assets directly from the assets directory. Instead you have to access the existing assets that is brought to .tmp/public directory by Grunt at time of sails lift ing
THE Problems
(Available but Volatile) If you upload a file (say image) anywhere inside .tmp/public
directory, your file (image) is going to erase at next sails lift
(Unavailability) If you upload a file in any other custom directory- say: ./assets/images, the uploaded file will not be available immediately but at next sails lift it will be available. Which doesn't makes sense because - cant restart server each time files gets uploaded in production.
MY SOLUTION (say I want to upload my images in ./assets/images dir)
Upload the file say image.ext in ./tmp/public/images/image.ext (available and volatile)
On upload completion make a copy of the file image.ext to ./assets/images/*file.ext (future-proof)
CODE
var uploadToDir = '../public/images';
req.file("incoming_file").upload({
saveAs:function(file, cb) {
cb(null,uploadToDir+'/'+file.filename);
}
},function whenDone(err,files){
if (err) return res.serverError(err);
if( files.length > 0 ){
var ImagesDirArr = __dirname.split('/'); // path to this controller
ImagesDirArr.pop();
ImagesDirArr.pop();
var path = ImagesDirArr.join('/'); // path to root of the project
var _src = files[0].fd // path of the uploaded file
// the destination path
var _dest = path+'/assets/images/'+files[0].filename
// not preferred but fastest way of copying file
fs.createReadStream(_src).pipe(fs.createWriteStream(_dest));
return res.json({msg:"File saved", data: files});
}
});
I dont like this solution at all but yet it saved more of my time and it works perfectly in both dev and prod ENV.
Thanks
Sails uses grunt to handle asset syncing. By default, the grunt-watch task ignores empty folders, but as long as there's at least one file in a folder, it will always sync it. So the quickest solution here, if you're intent on using the default static middleware to server your uploaded files, is to just make sure there's always at least one file in your assets/uploads folder when you do sails lift. As long as that's the case, the uploads folder will always be synced to your .tmp/public folder, and anything that's uploaded to it subsequently will be automatically copied over and available immediately.
Of course, this will cause all of your uploaded files to be copied into .tmp/public every time your lift Sails, which you probably don't want. To solve this, you can use the symlink trick #bredikhin posted in his answer.
Try to do this:
npm install grunt-sync --save-dev --save-exact
uncomment the line: // grunt.loadNpmTasks('grunt-sync');
usually it is near to the end of the file /tasks/config/sync.js.
lift the App again
Back to the Original answer
I was using node version 10.15.0, and I faced same problem. I solved this by updating to current version of node(12.4.0) and also updated npm and all the node modules. After this, I fixed the vulnerabilities(just run 'npm audit fix') and the grunt error that was coming while uploading the images to assets/images folder was fixed.
Try out this implementation
create a helper to sync the file
example of the filesync helper
// import in file
const fs = require('fs')
module.exports = {
friendlyName: 'Upload sync',
description: '',
inputs: {
filename:{
type:'string'
}
},
exits: {
success: {
description: 'All done.',
},
},
fn: async function ({
filename
}) {
var uploadLocation = sails.config.custom.profilePicDirectory + filename;
var tempLocation = sails.config.custom.tempProfilePicDirectory + filename;
//Copy the file to the temp folder so that it becomes available immediately
await fs.createReadStream(uploadLocation).pipe(fs.createWriteStream(tempLocation));
// TODO
return;
}
};
now call this helper to sync your files to the .temp folder
const fileName = result[0].fd.split("\\").reverse()[0];
//Sync to the .temp folder
await await sails.helpers.uploadSync(fileName);
reference to save in env
profilePicDirectory:path.join(path.resolve(),"assets/images/uploads/profilePictures/")
tempProfilePicDirectory:path.join(path.resolve(),".tmp/public/images/uploads/profilePictures/"),
also can try
process.cwd()+filepath