ユーザーがアップロードする添付ファイルを保存するための簡単なファイル入力がアプリケーションにあります。コントロールされた反応テキスト入力上にファイル拡張子を保存する
<input id='uploadFile' type='file' name="files" />
<label htmlFor='uploadFile' onClick={this.onFileClick}>File</label>
アップロードされたファイルのファイル名を変更できるテキスト入力もあります。
<input id={props.id} type='text' value={props.value} onChange={(event) => props.onChangeHandler(event)} />
input
はReduxのからの値を読み出し、その親からprops.value
を読み出します。すべて素晴らしいです。ただし、ユーザーはファイル拡張子を上書きすることができ、拡張子なしでファイルがアップロードされます。 Yikes!私の質問は、どのように制御されたテキスト入力でファイル拡張子を保存することができますです。私の現在の考え方は次のようなものが含ま:
// check the MIME type of the upload
let mimeType = attachmentswindow.uploadedAttachment.type;
// check the text input for presence of a "."
// if it's not there, we better add the extension!
let updatedAttachmentFilename = event.target.value.includes(".") ?
event.target.value :
event.target.value + '.' + mimeType.substring(mimeType.lastIndexOf("/") + 1);
// store the new file name in redux
dispatch(updateUploadedAttachmentFilename({ updatedAttachmentFilename }));
作品のこの種を、本当に、私はそれは不可能イベントにユーザがファイルの拡張子に触れるためにしたいのですが。 Reactで制御されたテキスト入力でこれを行う方法はありますか?助けを前にありがとう。
これが可能かどうかはわかりませんが、入力にファイル名(拡張子なし)を表示し、その拡張子をビューの外に保持しないのはなぜですか。ファイルをアップロードする必要がある場合にのみ使用します。 –