Is possible to load data from local xml file?
Here is my code:
var file;
jwplayer().onError(function() {
jwplayer().load({
file: file
});
jwplayer().play();
jwplayer().onComplete(function() {
if (doesConnectionExist()) {
location.reload();
}
});
});
The var file must be load from a xml file that contains http://localhost/error.mp4.
What should I use to do that?
Because each client may have a different location error file.
Related
I'm completely new to javascript. I have a .js (running on webserver) file with two options:
defaultUrl: {
value: "filename.pdf",
kind: OptionKind.VIEWER
},
and instead of filaname.pdf name I would like it to detect any .pdf file in current working folder (there will always be one, but each time with different filename) and return it's name here
The file is on shared web hosting - so I probably can run some .php code to find the filename
edit:
// If absolute URL from the remote server is provided, configure the CORS
// header on that server.
var url = 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/examples/learning/helloworld.pdf';
// Loaded via <script> tag, create shortcut to access PDF.js exports.
var pdfjsLib = window['pdfjs-dist/build/pdf'];
// The workerSrc property shall be specified.
pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';
// Asynchronous download of PDF
var loadingTask = pdfjsLib.getDocument(url);
loadingTask.promise.then(function(pdf) {
console.log('PDF loaded');
Assume you have this directory structure:
$ tree test
test
├── test-find-pdf.php
└── test.pdf
0 directories, 2 files
Then you can get all pdf files in the current working directory using glob(). To return the name of the first pdf file found modify your php script like this:
<?php
# file test-find-pdf.php
$allPdfFiles = glob("*.pdf");
echo $allPdfFiles[0];
?>
That way you can call it from your javascript with an XMLHttpRequest (aka Ajax request) like this:
<script>
var request = new XMLHttpRequest();
request.open("GET","test-find-pdf.php");
request.addEventListener('load', function(event) {
if (request.status >= 200 && request.status < 300) {
console.log(request.responseText);
} else {
console.warn(request.statusText, request.responseText);
}
});
request.send();
</script>
So on load of your html document the Ajax returns the result of the php file and prints it to the console F12 in your browser. From there you have to find a way to assign it to your json object.
Make sure that the path to your php file in request.open() is correct.
Further information on glob() can be found in the php manual.
I am trying to upload a zip file that contains an HTML file inside to firebase storage. I am using JSzip to zip the file. Here is how my code looks right now:
DownloadHandler = () => {
var zip = new JSZip();
zip.file("story.html", `<body>${this.state.html}</body>`);
zip.generateAsync({ type: "blob" }).then(function (blob) {
storage.ref("story").put(blob);
});
};
When I run the current code it uploads the zip but inside the zip, I am getting a document file and not an HTML file. Also, when I click this document file it says it is encoded. How can I modify my code so that when the file zips it zips an HTML file inside?
Figured it out. In my storage.ref("story").put(blob); I just need to specify the extension of the file so it needed to be storage.ref("story.zip").put(blob);
app.get('/',function(req,res){
res.sendFile('index.html');
});
How do i send a javascript file along with index.html back to the client browser for rendering?
You can't send 2 responses, but you could embed your javascript in your index.html file!
The index.html file should contain a reference to the js file in a <script> tag.
You only send the .html.
The browser parses it, sees the reference to the .js file and requests it then.
you can try this
getOptions = (id) => {
return {
root: `uploads/${id}' // specify the path and file Name from where you want to send file
dotfiles: 'deny',
}
}
res.sendFile(id, getOptions(req.body.id));
There exists a url which dynamically creates a file (zip) for download.
http://example.com/generateZipFile.php
In a browser, opening the url simply opens the download dialog box, and a user can save the file to their hard drive.
I need to automatically download this file using node.js
I have tried the following code:
var file = fs.createWriteStream("http://example.com/generateZip.php");
var request = http.get(URL, function(response) {
response.pipe(file);
});
However it only downloads the content of what appears to be a HTML redirect page to the current incantation of the zip file, not the zip file itself:
> <head><title>Document Moved</title></head> <body><h1>Object
> Moved</h1>This document may be found <a
> HREF="http://example.com/generated12345.zip">here</a></body>
I can not hard code the generated name of the zip file, as it is subject to change.
http module does not support redirection for queries. You can use request module:
require('request')
.get('http://example.com/generateZip.php')
.on('error', function(error) {
console.log(error)
})
.pipe(require('fs').createWriteStream(__dirname + '/tmp.file'))
My main program prompts the user to browse for a file in order to convert it using ffmpeg. This is the format of the file browsing:
<div>
<p class="lead">1. Select audio file for conversion ( mp3, wma):</p>
<div class="quick-center">
<div class="quick-drop-outer quick-left"><input id="inFile" type="file" id="inputFile"/></div>
</div>
</div>
and this is the code where to launch the file and convert it according to selection: not whole code supported because no need of file conversion:
document.getElementById('inFile').addEventListener('change', handleFileSelect, false);
function readInputFile(file) {
// disable conversion for the time of file loading
$('#convert').attr('disabled', 'true');
// load file content
var reader = new FileReader();
reader.onload = function(e) {
$('#convert').removeAttr('disabled');
fileName = file.name;
fileBuffer = e.target.result;
}
reader.readAsArrayBuffer(file);
}
function handleFileSelect(event) {
var files = event.target.files; // FileList object
// files is a FileList of File objects. display first file name
file = files[0];
console.log(file);
if (file) {
$("#drop").text("Drop file here");
readInputFile(file);
}
}
now, here is my problem, what I want to do is to upload the file directly from a selected folder (upload) where the audio files are already there. I want instead of browsing for the file, I want the last file in the upload folder to be uploaded instead of "inFile" so that conversion can happen.
how could that happen.
edit: A small brief about my project. the user records his voice using HTML5 and the link of that audio is uploaded using ajax and php into a folder named upload.what I simply want is instead of browsing that file, I want to write down the path of the file in the selected folder automatically once recording is done for conversion.so, instead of dropping the file by user, the file would be dropped and conversion starts from there.
help please.Thank you in advance
From JavaScript You dont have access to files and directories on host system.
Why?
Because is VERY IMPORTANT SECURITY feature to block reading Your disc for files from scripts.