public HttpStatusCode Upload( FileInfo mediaFile, string message, string keyword, string username, string twitter_id, ref string content )
{
// Message必須
if ( string.IsNullOrEmpty( message ) )
throw new ArgumentException( "'Message' is required." );
// Check filetype and size
if ( Array.IndexOf( multimediaExt, mediaFile.Extension.ToLower() ) > -1 )
{
if ( mediaFile.Length > TwitVideo.MaxMultiMediaFileSize )
throw new ArgumentException( "File is too large." );
}
else if ( Array.IndexOf( pictureExt, mediaFile.Extension.ToLower() ) > -1 )
{
if ( mediaFile.Length > TwitVideo.MaxPictureFileSize )
throw new ArgumentException( "File is too large." );
}
else
{
throw new ArgumentException( "Service don't support this filetype." );
}
// Endpoint(URI+Token)
const string URLBASE = "http://api.twitvideo.jp/oauth/upload/";
byte[] data = Encoding.ASCII.GetBytes( ApplicationSettings.TwitVideoConsumerKey.Substring(0, 9) + username );
byte[] bHash;
using (MD5CryptoServiceProvider md5provider = new MD5CryptoServiceProvider())
{
bHash = md5provider.ComputeHash( data );
}
string url = URLBASE + BitConverter.ToString( bHash ).ToLower().Replace( "-", "" );
// Parameters
Dictionary< string, string > param = new Dictionary< string, string >();
param.Add( "username", username );
if ( !string.IsNullOrEmpty( twitter_id ) )
param.Add( "twitter_id", twitter_id );
if ( !string.IsNullOrEmpty( keyword ) )
param.Add( "keyword", keyword );
param.Add( "type", "xml" );
param.Add( "message", message );
List< KeyValuePair< string, FileInfo > > binary = new List< KeyValuePair< string, FileInfo > >();
binary.Add( new KeyValuePair< string, FileInfo >( "media", mediaFile ) );
this.InstanceTimeout = 60000; // タイムアウト60秒
HttpWebRequest req = this.CreateRequest( HttpConnection.PostMethod, new Uri( url ), param, binary, false );
return this.GetResponse( req, out content, null, false );
}