23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

);<br />

"form-data", "-----------------------------7d44e178b0434")<br />

.then(function (uploadOperation) {<br />

// Start the upload and persist the promise<br />

upload = uploadOperation;<br />

promise = uploadOperation.startAsync().then(complete, error, progress);<br />

}<br />

The resulting request will look like this, very similar to what’s shown on the Flickr page (just with<br />

some extra headers):<br />

POST /website/multipartupload.aspx HTTP/1.1<br />

Cache-Control=no-cache<br />

Connection=Keep-Alive<br />

Content-Length=1328<br />

Content-Type=multipart/form-data; boundary="-----------------------------7d44e178b0434"<br />

Accept=*/*<br />

Accept-Encoding=gzip, deflate<br />

Host=localhost:60355<br />

User-Agent=Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0; Touch)<br />

UA-CPU=AMD64<br />

-------------------------------7d44e178b0434<br />

Content-Disposition: form-data; name="api_key"<br />

3632623532453245<br />

-------------------------------7d44e178b0434<br />

Content-Disposition: form-data; name="auth_token"<br />

436436545<br />

-------------------------------7d44e178b0434<br />

Content-Disposition: form-data; name="api_sig"<br />

43732850932746573245<br />

-------------------------------7d44e178b0434<br />

Content-Disposition: form-data; name="photo"; filename="tinysquare.jpg"<br />

Content-Type: image/jpeg<br />

{RAW JFIF DATA}<br />

-------------------------------7d44e178b0434--<br />

To run the sample and also see how this request is received, go to the MultipartUploadServer folder<br />

in this chapter’s companion content. Load website.sln into Visual Studio 2012 Express for Web, open<br />

MultipartUploadServer.aspx, and set a breakpoint on the first if statement inside the Page_Load<br />

method. Then start the site in Internet Explorer to open that page on a localhost debugging port. Copy<br />

that page’s URI for the next step.<br />

In the Multipart Upload example, paste that URI into the URI field and click the Start Multipart<br />

Transfer. When the upload operation’s startAsync is called, you should hit the server page breakpoint<br />

in Visual Studio for Web. You can step through that code if you want and examine the Request object;<br />

in the end, the code will copy the request into a file named multipart-request.txt on that server. This will<br />

contain the request contents as above, where you can see the relationship between how you set up the<br />

parts in the client and how they are received by the server.<br />

651

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!