Can I get upload path at runtime? - javascript

I need to get upload path of my uploaded files via jquery-file-uploader.
$('.new_plotphoto').fileupload({
done: function (e, data) {
var filess = data.files[0];
var filename = filess.name;
var filepath = filess.filepath;
console.log(filename); // this shows filename
console.log(filepath); // this shows undefined
}
});

Path of uploading file is a secure feature. From W3C File API docs about file name:
The name of the file; on getting, this must return the name of the
file as a string. There are numerous file name variations on different
systems; this is merely the name of the file, without path
information.
File path will be enabled only then you upload directory:
<input type=file multiple directory webkitdirectory onchange="console.log(this.files)">
In this case webkitRelativePath(for WebKit browsers) field of file object will be not empty. But it will show path only inside uploaded directory.
Also note that iOS browsers then uploading images always have this file name: image.jpg and no info about path.

Related

nodejs extract/decompress all content of .gz compressed files to directory

i have a file in the file system named temp.gz
the temp gzip file contains files and folder
i would like to extract them and have them in a folder like we would normally unzip a file in OS.
i have tried below code but thats not meant for extracting files to folder.
const unzip = zlib.createUnzip();
var input = fs.createReadStream(inFilename); /path/to/temp.gz
var output = fs.createWriteStream(outFilename); /path/to/output/folder
Above didnt work and i believe the reason is that it writes to a file and i have provided a directoy.
my requirement is extract files to directory.
zlib.gzip(responseData, (err, buffer) => {
// Calling gunzip method
zlib.gunzip(buffer, (err, buffer) => {
console.log(buffer,pathFileName);
fs.appendFileSync(pathFileName, buffer);
});
});
above i was trying to unzip as per the docs and write buffer to the output file and didnt create a folder as expected and didnt add the files there
sure i am missing something but not sure what.

Javascript create zip file

I am developing a website using react.js and admin-on-rest. One feature is allowing users to upload a pdf file.
I get the file as type FILE and want to get the file from FILE, compress it to zip, and then make it to type FILE.
So it should be FILE -> origin file -> zip file -> FILE from zip file.
I tried JSZip but still can not figure it out.
Any help is appreciated. Thanks
You can use JSZIP.
**use npm to install JSZIP
let zip = require('jszip')();
//hoping you have already taken input
let input = document.getElementById('fileInput'); // fileInput is id of my input element
let file = input.files[0];
let allZip = zip.file(file.name, file);
console.log(allZip)
Hi Garrick following are the steps you need to take.
1) handle fileupload in a rest wrapper
https://marmelab.com/admin-on-rest/RestClients.html#decorating-your-rest-client-example-of-file-upload
the above example is for image upload. But you will essentially be doing the same thing.
2)
const addUploadCapabilities = requestHandler => (type, resource, params) => {
if (type === 'UPDATE' && resource === 'posts') {
//use jszip to zip file here and package it however you need
// call the API with zipped file
} return requestHandler(type, resource, params);
};
There is a small app called jszip for this. Try, it would help. https://stuk.github.io/jszip/

node.js unzip file. file name is broken

I tried to unzip the file.
let zip = new AdmZip('./sample.zip')
zip.extractAllTo(path, true)
but,the name of the contents file is Japanese.
So file name is broken.
���̑�-�T�|�[�g�O
Any suggestions?

How to select Default folder location in File Upload Control?

I want to set the default path folder location has to be opened, Once I press the "browse" button in File Control. Please Help me.
This forum says it can't be done.
You are wanting to control the directory location that the browse
starts in and not the save path the file is uploaded to, correct?
I could be wrong but since the server never knows the file structure
of the client machine, the developers of that control probably did not
provide for that functionality.
COPIED: How to set physical path to upload a file in Asp.Net?
To use a folder outside of the application:
//check to make sure a file is selected
if (FileUpload1.HasFile)
{
//create the path to save the file to
string fileName = Path.Combine(#"E:\Project\Folders", FileUpload1.FileName);
//save the file to our local path
FileUpload1.SaveAs(fileName);
}
Of course, you wouldn't hardcode the path in a production application but this should save the file using the absolute path you described.
With regards to locating the file once you have saved it (per comments):
if (FileUpload1.HasFile)
{
string fileName = Path.Combine(#"E:\Project\Folders", FileUpload1.FileName);
FileUpload1.SaveAs(fileName);
FileInfo fileToDownload = new FileInfo( filename );
if (fileToDownload.Exists){
Process.Start(fileToDownload.FullName);
}
else {
MessageBox("File Not Saved!");
return;
}
}

How to push files in FileList?

My folder hierarchy looks like this:
a/a.XML
a/b/b.XML
I will select the a.XML file and read it. Now I have path of b.XML file.
My question is how to push this file in a FileList as I am not getting it through <input type="file">, since I only have the files path. I have searched for a solution, but I didn't found any help how to push a file in a FileList without it's input tag. I want my code to be run in google chrome.
My current code for reading a.XML file through an input tag looks like this:
if(filePath.files && filePath.files[0])
{
reader.onload = function (e)
{
output = e.target.result;
console.log("file path");
console.log(output);
}
}
If b.xml is placed in the FileList, then I can easily read this file so I only have b.xml path and I want to push this file in FileList interface.
It is not possible to add paths to a FileList because of security issues.

Categories

Resources