How to find mongoose-thumbnail "uploads" and "u" directories - angularjs

I'm working with mongoose-thumbnail to get an thumbnail of a image I upload, I done it exactly as in the github mongoose-thumbnail example and it works very well, below is my code
var mongoose = require('mongoose');
var thumbnailPluginLib = require('mongoose-thumbnail');
var path = require('path');
var thumbnailPlugin = thumbnailPluginLib.thumbnailPlugin;
var make_upload_to_model = thumbnailPluginLib.make_upload_to_model;
var uploads_base = path.join(__dirname, "uploads");
var uploads = path.join(uploads_base, "u");
var Schema = mongoose.Schema;
var ApplicationSchema = new Schema({
appName: String,
appTempPath:String,
userId : String,
status : String,
templateId: String,
appSettings:[{header: String, color: String, font: String, fontSize: Number, backImg: String}]
});
ApplicationSchema.plugin(thumbnailPlugin, {
name: "appIcon",
inline: true,
upload_to: make_upload_to_model(uploads, 'appIcon')
});
var Application = mongoose.model('Application', ApplicationSchema);
My problem is how do I find the "uploads" and "u" directories?? I can't find it anywhere in my directory, Please help.

It should be in the script_current_directory/uploads/u but it's not?
What does console.log(uploads) say? How about console.log(make_upload_to_model(uploads, 'appIcon'))
I'm not sure if your library creates directories that don't exist.
If all else fails, you can change the uploads directory or name to something arbitrary like XYZXYZXYZ and do a find . -name "XYZXYZXYZ" and it should turn up.
"the __dirname` keyword contains the path to the root directory of the currently executing script."

Related

How to replace Pipelet for ExportCustomerGroups in SFCC? (For removing Deprecated API usage)

function abc(){
var Site = require('dw/system/Site');
var utils= require('app_nars/cartridge/scripts/util/utils.js');
var mySite : String = (Site.getCurrent().getID() == "a") ? "" : "-" + Site.getCurrent().getID();
var customerGroupName : String ;
if (mySite == "A") {
customerGroupName = "A";
} else {
customerGroupName = "B";
}
var grpNam= utils.getGroup(customerGroupName);
var grpFileName = 'test';
/* No script api available for pipelet ExportCustomerGroups*/
var Pipelet = require('dw/system/Pipelet');
var PipeletExecutionResponse = new dw.system.Pipelet('ExportCustomerGroups').execute({
CustomerGroups: grpNam.iterator(),
ExportFile : grpFileName,
OverwriteExportFile:true
});
app.getView().render('path/templateName');
}
How can we replace the Pipelet ExportCustomerGroups here , i could see in documentation we can use job steps and there is no script replacement
You have to create with your own code, construct the xml needed while parsing the customers.[enter image description here][1]
Or you can use this step when configuring job if no custom code needed there:
[1]: https://i.stack.imgur.com/s1VQa.png

Find a specific Google Document in Drive

I am trying to write a script to get the URL of a specific yet dynamic Google Document in Drive. The Google Document is created every Tuesday with its date at the end of the title of the Google Document.
"TypeError: Cannot find function getUrl in object FileIterator." error shows on line var agendaURL = file.getUrl();. Not sure how to debug this.
var ssUrl = 'LINK BUFFERED';
var sheetName = 'SHEET1'; // name of sheet to use
var rangeName = 'C30'; // range of values to include
var dateRange = SpreadsheetApp.openByUrl(ssUrl)
.getSheetByName(sheetName)
.getRange(rangeName)
.getValues();
// NEED TO find how to find file by name below!
var file = DriveApp.getFilesByName("Weekly Agenda | " +dateRange);
var agendaURL = file.getUrl();
It is because you need to iterate through all of the files that meet the search criteria. The solution is here: https://developers.google.com/apps-script/reference/drive/drive-app
var files = DriveApp.getFilesByName("Weekly Agenda | " +dateRange);
while (files.hasNext()) {
var file = files.next();
var agendaURL = file.getUrl();
return agendaURL //for first one, or you can return each one, push to an array, etc...
}
The value which got by DriveApp.getFilesByName() is FileIterator. So it is necessary to retrieve the filename from the value as follows.
var filename = "Weekly Agenda | " + dateRange;
var file = DriveApp.getFilesByName(filename);
while (file.hasNext()) {
var file = files.next();
if (file.getName() == filename) {
var agendaURL = file.getUrl();
}
}

Downloading file in node.js into user specified path

i'm trying to download file using node.js and this is my code:
var file_url = req.body.filename;
var DOWNLOAD_DIR = './downloads/';
var options = {
host: url.parse(file_url).host,
port: 80,
path: url.parse(file_url).pathname
};
var file_name = url.parse(file_url).pathname.split('/').pop();
var file = fs.createWriteStream(DOWNLOAD_DIR + file_name);
http.get(options, function (resp) {
resp.on('data', function (data) {
file.write(data);
}).on('end', function () {
file.end();
console.log(file_name + ' downloaded to ' + DOWNLOAD_DIR);
delet(file_url);
});
});
here i'm giving DOWNLOAD_DIR manually so it is downloading to that
directory as it is localhost not a problem, but when i'm uploading this
code into server then the file should be downloaded to that particular
user's machine, so how to give path dynamically to DOWNLOAD_DIR variable
if the Downloads folder is in home directory (and you want to download in Downloads folder), then you can use
var path = require('path');
var file_url = req.body.filename;
var DOWNLOAD_DIR = path.join(process.env.HOME || process.env.USERPROFILE, 'downloads/');
var file_name = url.parse(file_url).pathname.split('/').pop();
var file_path = path.join(DOWNLOAD_DIR,file_name);
var file = fs.createWriteStream(file_path);
PS: While dealing with paths and files, always use path module of nodejs to generate path.

How to serve woff2 files from owin FileServer

Since font awesome 4.3, they added the fonts as woff2 format.
I'm guetting 404ed when trying to serve this file through owin :
app.UseFileServer(new FileServerOptions() {
RequestPath = PathString.Empty,
FileSystem = new PhysicalFileSystem(#"banana")
});
How do I serve woff2 mime type files through file server in owin ?
Two possibilities :
Serve all kind of file types :
var options = new FileServerOptions() {
RequestPath = PathString.Empty,
FileSystem = new PhysicalFileSystem(#"banana")
};
options.StaticFileOptions.ServeUnknownFileTypes = true;
app.UseFileServer(options);
Add woff2 mime type :
var options = new FileServerOptions() {
RequestPath = PathString.Empty,
FileSystem = new PhysicalFileSystem(#"banana")
};
((FileExtensionContentTypeProvider)options.StaticFileOptions.ContentTypeProvider)
.Mappings.Add(".woff2", "application/font-woff2");
app.UseFileServer(options);
Second options seems not as elegant but is nonetheless the best. Read why mime types are important.
You can avoid the not-very-nice casting by using inheritance:
FileServerOptions options = new FileServerOptions
{
StaticFileOptions =
{
ContentTypeProvider = new CustomFileExtensionContentTypeProvider(),
}
};
where
private class CustomFileExtensionContentTypeProvider : FileExtensionContentTypeProvider
{
public CustomFileExtensionContentTypeProvider()
{
Mappings.Add(".json", "application/json");
Mappings.Add(".mustache", "text/template");
}
}

Scala Lift - Save uploaded files to server directory

I'm currently storing images within the webapp folder of my Lift project, which I know will cause problems in future.
val path = "src/main/webapp/files/"
And the code I'm using to save it:
case Full(file) =>
val holder = new File(path, "test.txt")
val output = new FileOutputStream(holder)
try {
output.write(file)
} finally {
output.close()
}
}
What I'm trying to do is save the to the server root in an easily manageable folder called files, so SERVER_ROOT/files outside of the project folder.
Firstly how would I access the path to the root of the server so I can save them there?
Secondly how would I serve these files from my app, so I can display them on a page?
Thanks in advance, any help much appreciated :)
You have to store file to exact place on filesystem according to absolute path. I have written this code and it works, so maybe it helps you:
def storeFile (file : FileParamHolder): Box[File] =
{
getBaseApplicationPath match
{
case Full(appBasePath) =>
{
var uploadDir = new File(appBasePath + "RELATIVE PATH TO YOUR UPLOAD DIR")
val uploadingFile = new File(uploadDir, file.fileName)
println("upload file to: " + uploadingFile.getAbsolutePath)
var output = new FileOutputStream(uploadingFile)
try
{
output.write(file.file)
}
catch
{
case e => println(e)
}
finally
{
output.close
output = null
}
Full(uploadingFile)
}
case _ => Empty
}
}
and this is my getBaseApplicationPath function which finds out absolute path of local machine (server or your devel PC):
def getBaseApplicationPath: Box[String] =
{
LiftRules.context match
{
case context: HTTPServletContext =>
{
var baseApp: String = context.ctx.getRealPath("/")
if(!baseApp.endsWith(File.separator))
baseApp = baseApp + File.separator
Full(baseApp)
}
case _ => Empty
}
}

Resources