html4に簡単なアップロードフォームを書いています。通常、これは非常に単純なプロセスです。私が実行している問題は、画像データのためのものです。サーバーはbase64を期待していて、base64として送信するものは何も処理しないため、画像が壊れてしまいます。フォームに設定できる属性がありますか?もしそうでなければ、サーバーに送る前にbase64にデータをエンコードするためのjavascriptを設定できますか?タイプフィールドの入力をバイナリーではなく、ベース64でデータを送信します。
0
A
答えて
0
ここにはよく文書化されたbase64エンコーダ/デコーダhttp://hellerim.net/base64_src.phpへのリンクがあります。私はこのコードを修正しました(下記参照)ので、 "コア"クラスは必要ありませんでした。
/// BEGIN_DOC(base64).METHOD(decode)
///
// method RETURNTYPE base64.decode(String inp [, enum outType [, bool safe [, bool lax]]])
//
// Encode input data into a base64 character string.
//
// Function arguments:
// String inp: base64 encoded data string to be decoded.
// enum outType Optional. This parameter specifies the type of the output and determines
// how the input data is to be interpreted.:
// 0 - binary data; create a byte array (default)
// 1 - 8-bit character string, assuming 1-byte characters encoded in inp
// 2 - 16-bit (UniCode) character string, assuming 2-byte
// characters encoded in inp
// If 2 is passed to the function, but the number of base64 characters
// is odd, a value of null is returned.
// bool safe Optional. If this parameter is set to true, the standard base64
// character set is replaced with a modified version where
// the characters '+' and '/' are replaced with '-' and '_',
// repectively, in order to avoid problems with file system
// namings which otherwise could occur on some systems.
// By default, the value of this argument is assumed to be
// false.
// bool lax Optional. If set to true, the function skips all input characters which
// cannot be processed. This includes the character '=', too, if
// it is followed by at least one different character before the string
// ends. However, if skipping infeasible characters amounts to a number
// of allowed base64 characters which is not amultiple of 4,
// this is considered an error and null is returned.
// If lax is set to false (the default), null is returned
// whenever an infeasible character is found.
// The purpose of this parameter is to give support in cases
// where data has been base64 encoded and later on was folded by
// some other software, e.g. '\r\n\'s have been inserted in email.
// exchange.
// Return value: The function's processing result value is stored in a string or in
// a byte array before it is returned, depending on the value
// assigned to the type parameter. In each case, the value
// maybe empty but not null if no error occurred.
// Errors: Whenever an error occurs, null is returned. Parameter values
// not defined above are considered errors.
//
/// END_DOC
base64.decode = function(inp, outType, safe, lax) {
// do some argument checking
if (arguments.length < 1) return null;
if (arguments.length < 2) outType = 0; // produce character array by default
if (outType != 0 && outType != 1 && outType != 2) return null;
if (arguments.length >= 3 && safe != true && safe != false) return null;
var sEnc = (arguments.length >= 3 && safe) ? this.encStringS : this.encString; // select encoding character set
if (arguments.length >= 4 && lax != true && lax != false) return null;
var aDec = {}; // create an associative array for decoding
for (var p = 0; p < sEnc.length; p++) { // populate array
aDec[sEnc.charAt(p)] = p;
}
var out = (outType == 0) ? [] : '';
lax = (arguments.length == 4 && lax); // ignore non-base64 characters
var l = 0; // work area
var i = 0; // index into input
var j = 0; // sextett counter
var c = 0; // input buffer
var k = 0; // index into work area
var end = inp.length; // one position past the last character to be processed
var C = '';
// check input
if (lax) {
var inpS = ''; // shadow input
var ignore = false; // determines wether '=' must be counted
var cnt = 0;
for (var p = 1; p <= inp.length; p++) { // check and cleanup string before trying to decode
c = inp.charAt(end - p);
if (c == '=') {
if (!ignore) {
if (++cnt > 1) ignore = true;
} else {
continue;
}
} else if (undefined != aDec[c]) { // the character is base64, hence feasible
if (!ignore) ignore = true; // no more '=' allowed
inpS = c + inpS; // prepend c to shadow input
}
}
for (var p = 0; p <= cnt; p++) { // at most cnt '=''s were garbage, a number in
if (p == 2) return null; // [inpS.length, inpS.length + cnt] must be a
if ((inpS.length + cnt) % 4 == 0) break; // multiple of 4
}
if (inpS.length % 4 == 1) return null; // must be 0, 2, or 3 for inpS to contain correctly base64 encoded data
inp = inpS; // inp now contains feasible characters only
end = inp.length;
} else {
if (inp.length % 4 > 0) return null; // invalid length
for (var p = 0; p < 2; p++) { // search for trailing '=''s
if (inp.charAt(end - 1) == '=') {
end--;
} else {
break;
}
}
}
// convert
for (i = 0; i < end; i++) {
l <<= 6; // clear space for next sextett
if (undefined == (c = aDec[inp.charAt(i)])) return null; // lax must be false at this place!
l |= (c & 0x3f); // append it
if (j == 0) {
j++;
continue; // work area contains incomplete byte only
}
if (outType == 2) {
if (k == 1) { // work area contains complete double byte
out += String.fromCharCode(l >> (2 * (3 - j))); // convert leftmost 16 bits and append them to string
l &= ~(0xffff << (2 * (3 - j))); // clear the 16 processed bits
}
k = ++k % 2;
} else { // work area contains complete byte
if (outType == 0) {
out.push(l >> (2 * (3 - j))); // append byte to array
} else {
out += String.fromCharCode(l >> (2 * (3 - j))); // convert leftmost 8 bits and append them to String
}
l &= ~(0xff << (2 * (3 - j))); // clear the 8 processed bits
}
j = ++j % 4; // increment sextett counter cyclically
}
if (outType == 2 && k == 1) return null; // incomplete double byte in work area
return out;
}
+0
私はjavascriptのbase64クラスを持っていますが、私はちょうどjavascriptにファイルの内容を取得するのに苦労しています – nick
関連する問題
- 1. GDBでパイプライン入力を最初にではなく、ブレークポイントで送信します。
- 2. 入力時ではなくComboBoxのonFocusを送信する
- 3. html隠し入力タイプ - ベース64値
- 4. アップロードしたファイルを送信し、ajaxでデータを入力する
- 5. 入力フィールドに入力し、cURLで送信しますか?
- 6. 入力しないでフォームを送信するには
- 7. 入力時にPHPフォームがMySQLにデータを送信しない
- 8. AJAXの複数の入力がPHPにデータを送信または送信しない
- 9. Jqueryで入力フィールドにデータを入力しても、サーバーにデータが送信されない
- 10. JQuery:送信ボタンを押さなくてもデータを送信できますか?
- 11. IE11の入力送信ボタンをクリックしてフォームを送信できません
- 12. フォームなしで入力の値を送信する
- 13. URLを入力し、パラメータとして入力しないでフォームを送信してください
- 14. キーボード入力をバッチコマンドで送信する
- 15. Ajaxオートコンプリート入力フィールド無しのデータが送信されない
- 16. Springでのフォーム入力ではなく、コントローラへの変数の送信方法
- 17. AngularJSで空の入力フォームを送信
- 18. Jqueryモバイルフォームは送信しないでくださいまた、PHPスクリプトへの入力を投稿します
- 19. 入力キーでフォームを送信する/送信ボタン
- 20. jQuery .submit()はFirefoxで入力サブミットを送信しません
- 21. 入力フォームとスクラップページ、Python、リクエストライブラリでPOSTデータを送信
- 22. ベース64はフォームファイルをエンコードします
- 23. HTMLフォームで送信ボタンがない場合は(入力で)送信できないのは本当ですか?
- 24. VBA、Outlookなし、64ビットExcelで電子メールを送信する
- 25. バーチャルキーボードからdivまたは入力からdivへリアルタイムでデータを送信
- 26. HTML入力チェックボックスフォームを送信するときに 'True'ではなく 'On'を返します。
- 27. JavaScriptでCodemirrorデータを正しく送信できない
- 28. アドレスバー経由でデータを正しく送信できない
- 29. データを入力した後にメッセージを送信
- 30. 入力タイプをCSSで送信する - すべての入力ではなく、私はhtmlを変更することはできません
http://stackoverflow.com/questions/934012/get-image-data-in-javascript – ogur
それに伴う問題は、それが私の知る限り承知しているとして、HTMLで、キャンバスを使用しています5のみ、私はhtml 4ですべてを行うことができる必要があります。 – nick
それは難しいかもしれません。不可能でさえ。 JSはファイルを扱うようには設計されていません。あなたがキャンバスを使うことができない、またはサーバ側でそれを作れない場合は、おそらくフラッシュが解決されます。 – ogur