I’m using mootools request to push image data to a server to import images. My question is how to determine if an image path is valid before completing the request?
Here’s what I have now–
function doUpload(){
var remoteFile = document.id('uploadRemote').get('value');
var imageRequest = new Request({
url:'index.php',
method: 'post',
data: 'path='+remoteFile,
onRequest: function() {
console.log(remoteFile);
var myimage = Asset.image(remoteFile,
{
//onError: imageRequest.cancel() // <-- this doesn't work either
onError: this.cancel()
}
);
},
onSuccess: function(response) {
alert(response);
}
}).send();
}
document.id('submit').addEvent('click', function(){
doUpload();
});
I’m trying to use Asset.image to test if a path is truly an image– then if it’s not, to cancel the request. However, it’s not working out.
Any hints on what I’m doing wrong? Thanks!
You can’t get the path to the selected file from an
<input type="file" />. So, you won’t be able to load it before you upload it. The best you can do is to check the file extension.Edit: Perhaps the problem is with this line:
It should be: