2 using System.Collections.Generic;
9 namespace Azyobuzi.HatenaDiaryClient.Models.Hatena
11 public class HatenaFotolife
13 private string userName;
14 private string password;
16 public HatenaFotolife(string userName, string password)
18 this.userName = userName;
19 this.password = password;
22 public FotolifeEntry Upload(string title, string fileName, string folder = null)
26 switch (Path.GetExtension(fileName).TrimStart('.').ToLower())
30 mimeType = "image/jpeg";
33 mimeType = "image/gif";
36 mimeType = "image/png";
39 mimeType = "image/x-bmp";
42 mimeType = "video/quicktime";
47 mimeType = "video/mpeg";
50 mimeType = "video/x-ms-wmv";
53 mimeType = "video/avi";
56 mimeType = "video/x-flv";
60 mimeType = "video/3gpp";
63 mimeType = "video/3gpp2";
66 throw new ArgumentException("対応してないファイルです。");
70 var entry = new XElement(XmlNamespaces.Atom02Spec + "entry",
71 new XElement(XmlNamespaces.Atom02Spec + "title", title),
72 new XElement(XmlNamespaces.Atom02Spec + "content",
73 new XAttribute("mode", "base64"),
74 new XAttribute("type", mimeType),
75 Convert.ToBase64String(File.ReadAllBytes(fileName)))
78 if (!string.IsNullOrEmpty(folder))
79 entry.Add(new XElement(XmlNamespaces.DublinCore + "subject", folder));
81 var reXml = WsseAtomConnection.Post(
82 "http://f.hatena.ne.jp/atom/post",
84 Encoding.GetEncoding("shift_jis"),
87 return new FotolifeEntry(reXml.Root, false);