2

It would appear that FileReference.upload() is the only way in which you can upload a file to the server in Flash and get feedback about its upload state via a PROGRESS callback. All other methods just go off into the ether and come back when the file upload is completed.

Unfortunately, FileReference appears to insist that a user select the file to be uploaded. There doesn't appear to be a mechanism by which to set the file through code. The reason I need this is that I'm allowing the user to upload massive files and am uploading them in chunks, so, I want to just pack a chunk of data into a FileReference (maybe 5 or 10 megs) and send that off and watch it go. Does anyone have any thoughts on whether it's possible to manually load data into a FileReference object? The data property is read-only, sadly. Any and all advice on this will be treated with kindness :)

4

2 に答える 2

1

投稿者は、ユーザーのシステムからランダムなファイルをアップロードしようとしているのではなく、ファイル参照を取得してカスタム データをアップロードしようとしていますが、残念ながらそれはできません。

このリンクが非常に役立つことがわかりました: http://labs.findsubstance.com/2008/04/03/as3-upload-encode-images/

于 2012-03-19T23:49:34.493 に答える
0

はい、それは不可能です。これはセキュリティ対策です。つまり、ユーザーが明示的に送信するように選択しない限り、ユーザーの PC からランダムなファイルを送信することはできません。

ただし、別の方法で設計すれば、アップロードを監視できます。たとえば、URLStream、Socket、または NetConnection を使用して、必要なデータを送信し、必要な方法で応答するようにサーバーを構成できます。たとえば、URLStream は、データの送受信の両方に使用できる読み取り/書き込みストリームを提供します。次に、ある種のバッファーでそれを使用できます。バッファーのコンテンツを送信し、サーバーがデータを受信したことを確認するのを待ち、バッファーを補充し、繰り返します。

編集:では、AIRアプリケーションについて話していると思います(ファイルについて言及しているため)?おそらく、FileStream を使用してファイルを開き、受信したばかりのデータのチャンクを FileReference.upload() を使用して送信したいと考えています。これは正しいですか? それでは、FileReference は黙ってそれを行うことができないようです。それでも、URLStream を使用して、アップロードしたいデータの大きなチャンクを分割し、たとえば 100 の部分に分割してから、各部分を後で送信します。 receiving OK from the server script configured to accept it. Usually, file upload is handled directly by the HTTP server, but your case will require some extra work, namely, launching a script that would negotiate "package" size, receive the packages and acknowledge the reception. This may be less trivial for server scripts that might time out, but there certainly must be a solution to this.

Alternatively, you could configure your HTTP server to serve socket policy once it receives a socket policy request, afterwards, you could connect with the Socket and just copy the multipart-form-data kind of request usually sent through FileReference or similar HTML control. (I'd probably choose this way, if it wasn't a shared hosting or anything else that would prevent me from being able to configure the server).

于 2012-02-12T07:24:34.300 に答える