PrepAway - Latest Free Exam Questions & Answers

You develop an HTML5 application that allows users to upload files from their local computers.

You develop an HTML5 application that allows users to upload files from their local computers.

The user interface must remain responsive during the upload.

You need to implement the file upload functionality for the application.

Which two actions should you perform? (Each correct answer presents a complete solution. Choose two.)

A. Use an HTML form with a file type INPUT element that targets a hidden IFRAME element.

B. Use a file type INPUT element, and then use the Web Storage API to upload the file.

C. Usea FormData object and upload the file by using XMLHttpRequest.

D. Register the file protocol by using protocol handler registration API and then upload the file by using XMLHttpRequest.

E. Use the FileSystem API to load the file, and then use the jQuery post method to upload the file to the server.

Explanation:

B: Example (notice the web storage api upload.aspx):

<

!DOCTYPE html

>

<

html

>

<

head

>

<

title

>

Upload Files using XMLHttpRequest – Minimal

<

/title

>

<

/head

>

<

body

>

<

form id=-form1- enctype=-multipart/form-data- method=-post- action=-Upload.aspx-

>

<

div class=-row-

>

<

label for=-fileToUpload-

>

Select a File to Upload

<

/label

><

br /

>

<

input type=-file- name=-fileToUpload- id=-fileToUpload- onchange=-fileSelected();-/

>

<

/div

>

<

div id=-fileName-

><

/div

>

<

div id=-fileSize-

><

/div

>

<

div id=-fileType-

><

/div

>

<

div class=-row-

>

<

input type=-button- onclick=-uploadFile()- value=-Upload- /

>

<

/div

>

<

div id=-progressNumber-

><

/div

>

<

/form

>

<

/body

>

<

/html

>

D:

* Because were using XMLHttpRequest, the uploading ishappening in the background. The page the user is on remains intact. Which is a nice feature to have if your business process can work with it.

* The XMLHttpRequest object has gotten a facelift in the Html5 specifications. Specifically the XMLHttpRequest Level 2 specification (currently the latest version) that has included the following new features:

Handling of byte streams such as File, Blob and FormData objects for uploading and downloading

Progress events during uploading and downloading

Cross-originrequests

Allow making anonymous request – that is not send HTTP Referer

The ability to set a Timeout for the Request

One Comment on “You develop an HTML5 application that allows users to upload files from their local computers.


Leave a Reply