[英]How to modify submitted file client-side in JavaScript/jQuery
我想在用戶到達服務器之前修改客戶端用戶提交的文件。 要對其進行修改,我想使用將與JavaScript通信的Flash小程序。
<form action="" method="post" enctype="multipart/form-data">
<input type="file" id="id_file">
<input type="submit" value="Submit">
</form>
有可能做到嗎? 如果是的話,我將不勝感激任何提示,應該怎么做:)
我應該將其轉換為字符串嗎? 還是JS帶有一些使這些操作更容易的功能?
$( "form" ).change(function(x) {
//pass file input to Flash applet
x.preventDefault();
flashApplet.proceed($('#id_file').value);
});
function callback(modified_file) {
// Flash applet has modified the file
// Now submit the form with a new, modified file
$('#id_file').value = modified_file;
trigger_submit();
}
該文件可以是視頻,音頻或圖像。
不要使用“提交”按鈕,而是使用偽裝成看起來像“提交”按鈕的普通按鈕,然后您可以檢查單擊該按鈕的時間,處理您的工作,然后使用
document.getElementById("myform").submit();
我將用以下代碼替換您當前的html:
<form action="" method="post" enctype="multipart/form-data" id="myform">
<input type="file">
<button id="submit">Submit</button>
</form>
然后js:
document.getElementById('submit').onclick = function() {
//do your flash stuff
};
function callback(){
//here we submit the form
document.getElementById("myform").submit();
// because the file itself has been modified, this is all we need to do.
}
基本上,使用一個錯誤的提交按鈕,首先要執行的操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.