上传前检查图片是否有效--mootools
我正在使用 mootools 请求将图像数据推送到服务器以导入图像。我的问题是如何在完成请求之前确定图像路径是否有效?
这就是我现在所拥有的 -
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();
});
我尝试使用 Asset.image 来测试路径是否确实是图像 - 如果不是,则取消请求。然而,这并没有成功。
关于我做错了什么的任何提示吗?谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法从
获取所选文件的路径。因此,在上传之前您将无法加载它。您能做的最好的事情就是检查文件扩展名。
编辑:也许问题出在这一行:
它应该是:
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: