Getting the local path of file uploaded via Box uploader
AnsweredWe've added the Box ContentUploader to our application, and we need to get the duration of videos that we are uploading. Is there a way to get the local path of a file once it is dropped in the uploader window? I am able to do so by creating an uploader of my own and then running the following JS:
var myVideos = [];
window.URL = window.URL || window.webkitURL;
document.getElementById('fileUp').onchange = setFileInfo;
function setFileInfo() {
var files = this.files;
myVideos.push(files[0]);
var video = document.createElement('video');
video.preload = 'metadata';
video.onloadedmetadata = function() {
window.URL.revokeObjectURL(video.src);
var duration = video.duration;
myVideos[myVideos.length - 1].duration = duration;
updateInfos();
}
video.src = URL.createObjectURL(files[0]);;
}
function updateInfos() {
var infos = document.getElementById('infos');
infos.textContent = "";
for (var i = 0; i < myVideos.length; i++) {
infos.textContent += myVideos[i].name + " duration: " + myVideos[i].duration + '\n';
}
}
All I need is the local path
-
Official comment
Hey Noah,
Can you expand further on what you mean by local path?
Thanks.
Alex, Box Developer Advocate
Comment actions -
Alex,
Apologies, maybe I mean relative path. What I am trying to do, once a file is dropped in the Box ContentUploader, is to programmatically grab the path of the file on the user's computer, i.e. /Users/user/Desktop/filename.mp4 or whatever it might be. I would then use that path to set the value of 'fileUp' in the code snippet in order to get the file duration. So far I have tried uploader.on('complete'...) and uploader.on('upload'...) but those only seem to return information from the uploaded file in Box. I am hoping there is some way that the ContentUploader knows the file's location that it is uploading from.
Thanks,
Noah
Please sign in to leave a comment.
Comments
4 comments