<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>HttpPut &#8211; WiredPrairie</title>
	<atom:link href="blog/archives/tag/httpput/feed" rel="self" type="application/rss+xml" />
	<link>/blog</link>
	<description>Yet another tech blog.</description>
	<lastBuildDate>Tue, 31 Jul 2012 12:33:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0</generator>
<site xmlns="com-wordpress:feed-additions:1">193486638</site>	<item>
		<title>Simple Node based Http Put simulator</title>
		<link>/blog/index.php/archives/1693</link>
		
		<dc:creator><![CDATA[Aaron]]></dc:creator>
		<pubDate>Tue, 31 Jul 2012 12:29:50 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ExpressJs]]></category>
		<category><![CDATA[HttpPut]]></category>
		<category><![CDATA[NodeJs]]></category>
		<guid isPermaLink="false">/blog/?p=1693</guid>

					<description><![CDATA[It’s great what you can accomplish in a few lines of code. The Node based source code below uses express to create a mini view-based web server along with a mock Http Put file upload destination. /** * Module dependencies. */var express = require('express') , routes = require('./routes') , http = require('http') , path = [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>It’s great what you can accomplish in a few lines of code. The <a href="http://nodejs.org/" target="_blank">Node</a> based source code below uses <a href="http://expressjs.com/" target="_blank">express</a> to create a mini view-based web server along with a mock Http Put file upload destination. </p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; direction: ltr; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><br /><span style="color: #008000">/**</span><br /><span style="color: #008000"> * Module dependencies.</span><br /><span style="color: #008000"> */</span><br /><br />var express = require(<span style="color: #006080">'express'</span>)<br />  , routes = require(<span style="color: #006080">'./routes'</span>)<br />  , http = require(<span style="color: #006080">'http'</span>)<br />  , path = require(<span style="color: #006080">'path'</span>);<br /><br />var app = express();<br /><br />app.configure(function(){<br />  app.set(<span style="color: #006080">'port'</span>, process.env.PORT || 8080);<br />  app.set(<span style="color: #006080">'views'</span>, __dirname + <span style="color: #006080">'/views'</span>);<br />  app.set(<span style="color: #006080">'view engine'</span>, <span style="color: #006080">'jade'</span>);<br />  app.use(express.favicon());<br />  app.use(express.logger(<span style="color: #006080">'dev'</span>));<br />  app.use(express.bodyParser());<br />  app.use(express.methodOverride());<br />  app.use(app.router);<br />  app.use(express.<span style="color: #0000ff">static</span>(path.join(__dirname, <span style="color: #006080">'public'</span>)));<br />});<br /><br />app.put(<span style="color: #006080">'/upload/:fileUpload'</span>, function(req, res, next){<br />    console.log(<span style="color: #006080">'uploading!'</span>);<br />    res.send(<span style="color: #006080">'OK'</span>, { <span style="color: #006080">'Content-Type'</span>: <span style="color: #006080">'text/plain'</span> }, 200);<br />});<br /><br />app.configure(<span style="color: #006080">'development'</span>, function(){<br />  app.use(express.errorHandler());<br />});<br /><br />app.get(<span style="color: #006080">'/'</span>, routes.index);<br /><br />http.createServer(app).listen(app.get(<span style="color: #006080">'port'</span>), function(){<br />  console.log(<span style="color: #006080">&quot;Express server listening on port &quot;</span> + app.get(<span style="color: #006080">'port'</span>));<br />});<br /></pre>
<p></div>
<p>Using <a href="http://www.jetbrains.com/webstorm/" target="_blank">WebStorm</a>’s Node/Express template, I only added 4 lines:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas,&#39;Courier New&#39;, courier, monospace; direction: ltr; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">app.put(<span style="color: #006080">'/upload/:fileUpload'</span>, function(req, res, next){<br />    console.log(<span style="color: #006080">'uploading!'</span>);    <br />    res.send(<span style="color: #006080">'OK'</span>, { <span style="color: #006080">'Content-Type'</span>: <span style="color: #006080">'text/plain'</span> }, 200);<br />});<br /></pre>
<p></div>
<p>These 4 lines added a new route/path for uploading a file in the pattern of /upload/ {fileName}.</p>
<p>The response was “OK.” </p>
<p>I’d tried this same thing using ASP.NET MVC 4 (with Razor), but was stumped by the error when trying to use HttpPut on an Action in the controller.</p>
<p>I was using this end-point as a mock-upload destination for my SmugMug application, <a href="http://www.wiredprairie.us/SnugUp/" target="_blank">SnugUp</a>. I wanted to eliminate the uploading process as it’s time consuming and messes up my SmugMug galleries! <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="blog/wpcontent/uploads/2012/07/wlEmoticon-smile.png" /></p>
<p>The C# code is simple as it uses HttpWebRequest:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; direction: ltr; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">HttpWebRequest uploadRequest = (HttpWebRequest)WebRequest.Create(ApplicationConstants.UploadUrl + <span style="color: #006080">&quot;photo.jpg&quot;</span>);<br /><br />uploadRequest.Timeout = (<span style="color: #0000ff">int</span>)10080 * 60 * 1000; <span style="color: #008000">// 7 days </span><br />uploadRequest.Method = <span style="color: #006080">&quot;PUT&quot;</span>;<br />uploadRequest.UserAgent = ApplicationConstants.UserAgent;<br />uploadRequest.ContentLength = fi.Length;<br />uploadRequest.KeepAlive = <span style="color: #0000ff">true</span>;</pre>
<p></div>
<p>(SmugMug grabs the file name from a custom Http Header, so, the put URL is always “photo.jpg”.)</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1693</post-id>	</item>
	</channel>
</rss>
