SWFUpload 是如何工作的?
我下面的代码有效,除了上传部分。到目前为止,我可以毫无问题地加载脚本,并且当用户单击上传按钮时,文件对话框将打开。
但是,我想做的是将文件分配给包含其他文本输入和文本区域元素的表单。
基本上我正在尝试这样做:
- 用户用值填充表单(即填充文本输入、文本区域字段)
- 用户使用 SWFUpload 选择文件
- 用户提交表单
是否可以将文件挂钩到文件输入元素那么当手动提交表单时,所有值都会一次性发送吗?
据我所知,SWFUpload 用于在后台自动提交文件......这可以在一种表单上手动完成吗?
$('.swfupload-control').swfupload({
// File Upload Settings
file_size_limit : "102400", // 100MB
file_types : "*.*",
file_types_description : "All Files",
file_upload_limit : "10",
file_queue_limit : "0",
// Button Settings
button_image_url : "/images/upload_song.gif", // Relative to the SWF file
button_placeholder_id : "spanButtonPlaceholder",
button_width: 186,
button_height: 32,
// Flash Settings
flash_url : "/javascripts/swfupload/swfupload.swf"
});
$('.swfupload-control')
.bind('swfuploadLoaded', function(event){
$('#log').append('<li>Loaded</li>');
})
.bind('fileQueued', function(event, file){
$('#log').append('<li>File queued - '+file.name+'</li>');
//$('#song_attachment').val(file);
$('#update-media').parents('li').find('p').remove();
$('#update-media').parents('li').append('<p>'+(file.name.length >= 45 ? file.name.substr(0, 45) + '...' : file.name)+'</p>');
// start the upload since it's queued
//$(this).swfupload('startUpload');
})
.bind('fileQueueError', function(event, file, errorCode, message){
$('#log').append('<li>File queue error - '+message+'</li>');
})
.bind('fileDialogStart', function(event){
$('#log').append('<li>File dialog start</li>');
})
.bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
$('#log').append('<li>File dialog complete</li>');
})
.bind('uploadStart', function(event, file){
$('#log').append('<li>Upload start - '+file.name+'</li>');
})
.bind('uploadProgress', function(event, file, bytesLoaded){
$('#log').append('<li>Upload progress - '+bytesLoaded+'</li>');
})
.bind('uploadSuccess', function(event, file, serverData){
$('#log').append('<li>Upload success - '+file.name+'</li>');
})
.bind('uploadComplete', function(event, file){
$('#log').append('<li>Upload complete - '+file.name+'</li>');
// upload has completed, lets try the next one in the queue
$(this).swfupload('startUpload');
})
.bind('uploadError', function(event, file, errorCode, message){
$('#log').append('<li>Upload error - '+message+'</li>');
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,我不知道 SWF 上传,如果不相关,我准备删除这个答案...但是:
我在这里制作了两个应用程序: https://github.com/apneadiving/Pic-upload---Crop-in-Ajax
一个 Uploadify 和一个 jQuery-File-上传。
它们都满足您的需求(ajax 提交、多个文件上传)。我推荐 Jquery 文件上传,因为它是无闪存的。
我还在这里写了一个教程: https: //github.com/blueimp/jQuery-File-Upload/wiki/jQuery-File-Upload-for-Rails-3
Sorry, I don't know SWF Upload and am ready to delete this answer if irrelevant... BUT:
I made two apps here: https://github.com/apneadiving/Pic-upload---Crop-in-Ajax
One with Uploadify and one with jQuery-File-Upload.
They both answer your needs (ajax submitting, multiple files upload). I would recommend Jquery file upload because it's flash-free.
I also wrote a tutorial here: https://github.com/blueimp/jQuery-File-Upload/wiki/jQuery-File-Upload-for-Rails-3
不,不可能将 SWFUpload 挂接到文件字段。
浏览器传统上不允许 Javascript 访问用户的文件系统(正在开发 API)。 SWFUpload 通过使用 Flash API 直接从用户的文件系统读取文件并将其流式传输到服务器来解决此问题。为此,Flash 需要直接处理文件系统上的文件,而它无法通过文件输入或 Javascript 获取该文件。
Firefox 对 Javascript File API 有一些支持,请参阅
https://developer.mozilla.org/en/using_files_from_web_applications
No, it's not possible to hook SWFUpload to a file field.
Browsers traditionally don't allow Javascript access to the user's filesystem (there are APIs in the works). SWFUpload gets around this by using Flash APIs to read the file directly from the user's filesystem, and streaming it to a server. To do this Flash needs direct handles to files on the filesystem, which it can't get through the file input or Javascript.
Firefox has some support for the Javascript File API, see
https://developer.mozilla.org/en/using_files_from_web_applications