ASP.NET MVC Saving to a specific folder on the client - javascript

I need to perform those operation on a MVC application:
The user select a file from a grid
The file need to be saved on a shared folder
The user modifies the file with Excel
The file is saved in the same shared folder
A server deamon will process the file
My main problem (and I don't know if I can use handle it) is to prompt the user proposing to save the file on a shared folder...is this possible? or in alternative can I do via javascript to open the file knowing the shared folder and file name?

If you have hosted your application on client's IIS and from your localhost you want to save file to client end.
look at these code, maybe it will help you.
if (!string.IsNullOrEmpty(Path))
{
FileUpload file = new FileUpload();
string Folder = HttpContext.Current.Server.MapPath(Path);
string Path = Path.Combine(Folder, File);
file.SaveAs(Path);
}
but the path of folder must be shared..

Via a web app it is not possible to save a file locally on a specific location on a client's computer due to security restrictions, as far as I know this is true for on all known browsers. With a shared folder or a folder on another machine with a valid path that is accessible from the IIS server you can.

Try this in the controller to get the path of default Download folder on a client end:
string filename = "YourFile.xls";
string path = GetDownloadPath();
private static string GetDownloadPath()
{
String path = String.Empty;
RegistryKey rKey = Registry.CurrentUser.OpenSubKey(#"Software\Microsoft\Internet Explorer\Main");
if (rKey != null)
path = (String)rKey.GetValue("Default Download Directory");
if (String.IsNullOrEmpty(path))
path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\downloads";
return path;
}

Related

Firebase admin when uploading files to storage through url: Error: ENOENT: no such file or directory

So I am trying to make a music app where people can upload music there. First, the client takes file and changes it to object url like this:
const track_src = URL.createObjectURL(track);
data.track_src = track_src;
await Req.post("/api/u/music/upload", data)
After that, the server receives the data and object url and uploads it to Firebase storage:
//track_src is the object url
await st.bucket(sid).upload(track_src, {
gzip: true,
metadata: {
cacheControl: 'public, max-age=31536000',
},
})
But I get error that says:
Error: ENOENT: no such file or directory, stat 'E:\Server\blob:http:\localhost:3000\91e53bb5-abf2-46b4-bd0c-268b242e93f3'
What you are trying to do is not possible. There are basically 2 methods of uploading files in Storage, you either have to :
Use the bucket().upload() method to upload, which accepts the path to your local file as the pathString parameter, so you need the actual file for this, not a url. This is the ideal option if you have the file stored locally and given the information you shared this might be the way to go for you. You can look at this answer for more information.
Use the bucket().file() to create an empty file in Storage and then use the file.createWriteStream() method to get a stream that can write to the file content. This can be a valid solution if you have the file in memory.
I would suggest you to take a look at this documentation for the methods offered for the bucket class and this documentation for the methods offered for the file class.

Anti virus scan for the files to be uploaded to the server - Node.js

How can i perform the scan for the files that comes as a request payload that if it is a potential virus or not? For ex. if some body saves a EICAR signature as a txt file and tries to upload it , i want to scan and reject it if in case it is a virus file.
I have checked clamscan but unable to understand what to specify in path here:-
const ClamScan = new NodeClam().init({
clamscan: {
path: '/usr/bin/clamscan', // Path to clamscan binary on your server
db: null, // Path to a custom virus definition database
scan_archives: true, // If true, scan archives (ex. zip, rar, tar, dmg, iso, etc...)
active: true // If true, this module will consider using the clamscan binary
}
});
Also i am uploading the files to amazon -s3 bucket which is integrated in object-store in SAP CLOUD PLATFORM.
The clamscan library available via NPM is a wrapper around the real clamscan program which is part of ClamAV.
You need to install ClamAV. That will include a program in a file named clamscan. You put the path to that program in that string.

How to fetch a file with its name (located with in a folder in local machine) and download it in browser with Node.js

How do I fetch a file from local machine with its file name and dowloand the same in Node.js without using third-party libraries?
I have seen this answer similar to this - How to download a file with Node.js (without using third-party libraries)?
but it shows to download using URL, but I need to fetch and download from my local, is it possible ?
node version I'm using is - 6.10.0
Not sure why you need "download" from your "local" - you're there already no?
If you need to read from your local in order to process or move it somewhere look at the File System module
https://nodejs.org/api/fs.html#fs_file_system
var fileStream = fs.createReadStream(filePath);
then you can do something with that file like upload it elsewhere
s3.upload({ Bucket: bucketName, Key: keyName, Body: fileStream});
hth

How to download a file from project/specific location using nodejs?

My requirement is I should be able to download an excel template on a click event, I thought I will put that excel template in some folder(docs) in my backend code(instead of generating it dynamically) and download that. Is that possible, if yes how? I am using express and node.
It is possible.
Probably you use Express framework. Express can serve static files under '/public' folder.
When user connect to this file, her/his browser will download file. But some browser can view files online. For example, Chrome can open PDF files.
If you want to force to download file you can use this simple code;
app.get('/download', function(req, res){
var file = __dirname + '/upload-folder/dramaticpenguin.MOV';
res.download(file); // Set disposition and send it.
});

Serve a file outside servers public scope to client with node.js

I've some files placed inside an upload folder which is not accessible without privileges and is outside from servers public scope.
If the owner want to download the previously uploaded file I need to pipe the file. That for I thought Streaming is the right way but I can't get it work.
So my actually working solution is the following example.
Is this still correct?
APP.fs.readFile(media.path, function(error, file) {
if (error === null) {
res.type(media.type);
res.send(file);
} else {
self.Component.send404(res);
}
});

Categories

Resources