예제 #1
0
        internal MWAMediaInfo NewMediaObject(string blogID, string userName, string password, MWAMediaObject mediaObject, HttpContext request)
        {
            ValidateRequest(userName, password);

            MWAMediaInfo mediaInfo = new MWAMediaInfo();

            string saveFolder = HostingEnvironment.MapPath("~/App_Data/Files");
            //saveFolder = Settings.Instance.FileDataStorePath;
            string fileName    = mediaObject.name;
            string mediaFolder = "";

            // Check/Create Folders & Fix fileName
            if (mediaObject.name.LastIndexOf('/') > -1)
            {
                mediaFolder  = mediaObject.name.Substring(0, mediaObject.name.LastIndexOf('/'));
                saveFolder  += mediaFolder;
                mediaFolder += "/";
                saveFolder   = saveFolder.Replace('/', Path.DirectorySeparatorChar);
                fileName     = mediaObject.name.Substring(mediaObject.name.LastIndexOf('/') + 1);
            }
            else
            {
                if (saveFolder.EndsWith(Path.DirectorySeparatorChar.ToString()))
                {
                    saveFolder = saveFolder.Substring(0, saveFolder.Length - 1);
                }
            }
            if (!Directory.Exists(saveFolder))
            {
                Directory.CreateDirectory(saveFolder);
            }
            saveFolder += Path.DirectorySeparatorChar;

            if (File.Exists(saveFolder + fileName))
            {
                // Find unique fileName
                for (int count = 1; count < 30000; count++)
                {
                    string tempFileName = fileName.Insert(fileName.LastIndexOf('.'), "_" + count);
                    if (!File.Exists(saveFolder + tempFileName))
                    {
                        fileName = tempFileName;
                        break;
                    }
                }
            }

            // Save File
            FileStream   fs = new FileStream(saveFolder + fileName, FileMode.Create);
            BinaryWriter bw = new BinaryWriter(fs);

            bw.Write(mediaObject.bits);
            bw.Close();

            // Set Url
            //TODO: ???? Jay
            string rootUrl = ""; // Utils.AbsoluteWebRoot.ToString();
            //if (BlogSettings.Instance.RequireSSLMetaWeblogAPI)
            //rootUrl = rootUrl.Replace("https://", "http://");

            string mediaType = mediaObject.type;

            if (mediaType.IndexOf('/') > -1)
            {
                mediaType = mediaType.Substring(0, mediaType.IndexOf('/'));
            }
            switch (mediaType)
            {
            case "image":
            case "notsent":     // If there wasn't a type, let's pretend it is an image.  (Thanks Zoundry.  This is for you.)
                rootUrl += "image.axd?picture=";
                break;

            default:
                rootUrl += "file.axd?file=";
                break;
            }

            mediaInfo.url = rootUrl + mediaFolder + fileName;
            return(mediaInfo);
        }
예제 #2
0
        internal MWAMediaInfo NewMediaObject(string blogID, string userName, string password, MWAMediaObject mediaObject, HttpContext request)
        {
            ValidateRequest(userName, password);

            MWAMediaInfo mediaInfo = new MWAMediaInfo();

            string saveFolder = HostingEnvironment.MapPath("~/App_Data/Files");
            //saveFolder = Settings.Instance.FileDataStorePath;
            string fileName = mediaObject.name;
            string mediaFolder = "";

            // Check/Create Folders & Fix fileName
            if (mediaObject.name.LastIndexOf('/') > -1)
            {
                mediaFolder = mediaObject.name.Substring(0, mediaObject.name.LastIndexOf('/'));
                saveFolder += mediaFolder;
                mediaFolder += "/";
                saveFolder = saveFolder.Replace('/', Path.DirectorySeparatorChar);
                fileName = mediaObject.name.Substring(mediaObject.name.LastIndexOf('/') + 1);
            }
            else
            {
                if (saveFolder.EndsWith(Path.DirectorySeparatorChar.ToString()))
                    saveFolder = saveFolder.Substring(0, saveFolder.Length - 1);
            }
            if (!Directory.Exists(saveFolder))
                Directory.CreateDirectory(saveFolder);
            saveFolder += Path.DirectorySeparatorChar;

            if (File.Exists(saveFolder + fileName))
            {
                // Find unique fileName
                for (int count = 1; count < 30000; count++)
                {
                    string tempFileName = fileName.Insert(fileName.LastIndexOf('.'), "_" + count);
                    if (!File.Exists(saveFolder + tempFileName))
                    {
                        fileName = tempFileName;
                        break;
                    }
                }
            }

            // Save File
            FileStream fs = new FileStream(saveFolder + fileName, FileMode.Create);
            BinaryWriter bw = new BinaryWriter(fs);
            bw.Write(mediaObject.bits);
            bw.Close();

            // Set Url
            //TODO: ???? Jay
            string rootUrl = ""; // Utils.AbsoluteWebRoot.ToString();
            //if (BlogSettings.Instance.RequireSSLMetaWeblogAPI)
            //rootUrl = rootUrl.Replace("https://", "http://");

            string mediaType = mediaObject.type;
            if (mediaType.IndexOf('/') > -1)
                mediaType = mediaType.Substring(0, mediaType.IndexOf('/'));
            switch (mediaType)
            {
                case "image":
                case "notsent": // If there wasn't a type, let's pretend it is an image.  (Thanks Zoundry.  This is for you.)
                    rootUrl += "image.axd?picture=";
                    break;
                default:
                    rootUrl += "file.axd?file=";
                    break;
            }

            mediaInfo.url = rootUrl + mediaFolder + fileName;
            return mediaInfo;
        }