Javascript Real AJAX uploader-将文件设置为手动上载
我使用真正的Ajax上传程序将文件从基于js/jQuery的前端上传到基于ASP.net的服务器端功能,通过文件对话框从文件系统中选择文件,该功能运行良好 但现在我需要找到一种方法来设置一个文件,我知道该文件的确切名称和本地路径,以便通过JS函数自动上载,而不是通过单击“选择文件”并从“文件”对话框中选择来手动选择该文件 我想我必须手动创建一个文件对象并将其推入文件数组,因为这样的描述才能获得fiel infos:但是我无法通过js函数设置文件并上传它 非常感谢您的帮助 提前谢谢 编辑: 感谢您的回复,这里是使用设备摄像头拍照并将其推入上传程序的文件对象的代码。。。 到目前为止,这是可行的,但我不知道如何更新fileuploader,因为它似乎没有这样做的方法。。。 因此,该文件位于文件列表file_list[0]中,包含我认为它需要的所有参数,但它没有显示在gui文件列表中 问候唐Javascript Real AJAX uploader-将文件设置为手动上载,javascript,file-upload,upload,ajaxuploader,Javascript,File Upload,Upload,Ajaxuploader,我使用真正的Ajax上传程序将文件从基于js/jQuery的前端上传到基于ASP.net的服务器端功能,通过文件对话框从文件系统中选择文件,该功能运行良好 但现在我需要找到一种方法来设置一个文件,我知道该文件的确切名称和本地路径,以便通过JS函数自动上载,而不是通过单击“选择文件”并从“文件”对话框中选择来手动选择该文件 我想我必须手动创建一个文件对象并将其推入文件数组,因为这样的描述才能获得fiel infos:但是我无法通过js函数设置文件并上传它 非常感谢您的帮助 提前谢谢 编辑: 感谢您
<code>
// photo functions
function getPhoto(){
navigator.camera.getPicture(onPhotoSuccess, onPhotoFail, {
quality: 50,
destinationType: Camera.DestinationType.NATIVE_URI
});
console.log("get photo ...");
}
function onPhotoSuccess(imageURI) {
console.log("photo taken ..." + imageURI);
$('#imgUploadArea').ajaxupload('clear');
var AU = $('#imgUploadArea').data('AU');
var file_list = AU.files; //get all the file objects
console.log("files: " + file_list.length);
// get the file object
window.resolveLocalFileSystemURL(imageURI, function(fileEntry) {
fileEntry.file(function(fileObj)
{
fileuploadShow("input.caseFormText.caseFormPhotoBtn");
// add the image
var capturedImg = new Object();
capturedImg.status = 0;
capturedImg.name = fileEntry.name;
capturedImg.path = fileEntry.fullPath;
capturedImg.size = fileObj.size;
capturedImg.filetype = "image.jpeg";
capturedImg.ext = "jpg";
capturedImg.AU = AU;
capturedImg.file = fileObj;
console.log("set image object to upload: " + capturedImg.path);
file_list.push(capturedImg);
console.log("files: " + file_list.length);
console.log("imgUpload ... imagedata path: " + file_list[0].path);
console.log("imgUpload ... imagedata name: " + file_list[0].name);
console.log("imgUpload ... imagedata status: " + file_list[0].status);
console.log("imgUpload ... imagedata size: " + file_list[0].size);
console.log("imgUpload ... imagedata filetype: " + file_list[0].filetype);
console.log("imgUpload ... imagedata ext: " + file_list[0].ext);
console.log("imgUpload ... imagedata file: " + JSON.stringify(file_list[0].file));
console.log("file added to filelist: " + file_list.length);
var files = $("#imgUploadArea").ajaxupload('getFiles');
console.log(JSON.stringify(files));
//$("#imgUploadArea").ajaxupload.('renderHtml');
//$("#imgUploadArea").ajaxupload('start');
});
});
}
function onPhotoFail(message) {
alert('Photo failed because: ' + message);
}
</code>
Don与此同时,我尝试了其他一些事情,比如将新图像定义为文件对象var capturedImg=new Object;但是没有任何运气,因为似乎不可能将文件添加到文件输入列表没有人可以帮助我解决此问题?出于安全原因,通常浏览器不允许在没有用户操作的情况下自动添加文件。要添加文件,始终需要用户操作选择或d&d。想想看,如果你能用js自动做到这一点,你就可以从用户的pc上下载文件