Beispiel #1
0
        protected MediaObjectInfo newMediaObjectLogicForWord(
            string blogid,
            string username,
            string password,
            FileData file)
        {
            UrlData         ud  = newMediaObjectLogic(blogid, username, password, file);
            MediaObjectInfo moi = new MediaObjectInfo();

            moi.url = ud.url;
            return(moi);
        }
    public async Task<MediaObjectInfo> NewMediaObjectAsync(string blogid, string username, string password, MediaObject mediaObject)
    {
      await EnsureUser(username, password);

      var bits = Convert.FromBase64String(mediaObject.bits);
      var op = _imageService.StoreImage(mediaObject.name, bits);

      op.Wait();
      if (!op.IsCompletedSuccessfully) throw op.Exception;
      var url = op.Result;

      // Create the response
      MediaObjectInfo objectInfo = new MediaObjectInfo();
      objectInfo.url = url;

      return objectInfo;
    }
Beispiel #3
0
        public async Task <MediaObjectInfo> NewMediaObjectAsync(string blogid, string username, string password, MediaObject mediaObject)
        {
            MediaObjectInfo mediaInfo = new MediaObjectInfo();

            if (await IsValidMetaWeblogUserAsync(username, password))
            {
                string fileName = Path.GetFileName(mediaObject.name);

                string PathOnly = Path.Combine(
                    _environment.WebRootPath,
                    "blogs",
                    $"{blogid}",
                    Path.GetDirectoryName(mediaObject.name));

                if (!Directory.Exists(PathOnly))
                {
                    Directory.CreateDirectory(PathOnly);
                }

                string FilePath = Path.Combine(PathOnly, fileName);

                var fileBytes = Convert.FromBase64String(mediaObject.bits);

                if (fileBytes != null)
                {
                    using (MemoryStream ms = new MemoryStream(fileBytes))
                    {
                        Bitmap bitmap = new Bitmap(ms);

                        bitmap.Save(FilePath);
                    }
                }

                mediaInfo.url = $@"{GetBaseUrl()}/blogs/{blogid}/{Path.GetDirectoryName(mediaObject.name).Replace("\\", @"/")}/{fileName}";
            }
            else
            {
                throw new Exception("Bad user name or password");
            }

            return(mediaInfo);
        }
Beispiel #4
0
        public MediaObjectInfo NewMediaObject(string blogid, string username, string password, MediaObject mediaObject)
        {
            EnsureUser(username, password).Wait();

            var filenameonly = mediaObject.name.Substring(mediaObject.name.LastIndexOf('/') + 1);

            var url   = $"https://wilderminds.blob.core.windows.net/img/{filenameonly}";
            var creds = new StorageCredentials(_config["BlobStorage:Account"], _config["BlobStorage:Key"]);
            var blob  = new CloudBlockBlob(new Uri(url), creds);
            var bits  = Convert.FromBase64String(mediaObject.bits);

            blob.UploadFromByteArrayAsync(bits, 0, bits.Length).Wait();

            // Create the response
            MediaObjectInfo objectInfo = new MediaObjectInfo();

            objectInfo.url = url;

            return(objectInfo);
        }
        public async Task <MediaObjectInfo> NewMediaObjectAsync(string blogid, string username, string password, MediaObject mediaObject)
        {
            await EnsureUser(username, password);

            var bits   = Convert.FromBase64String(mediaObject.bits);
            var result = await _imageService.StoreImage(mediaObject.name, bits);

            if (result.Success)
            {
                var url = result.ImageUrl;

                // Create the response
                MediaObjectInfo objectInfo = new MediaObjectInfo();
                objectInfo.url = url;

                return(objectInfo);
            }

            throw new MetaWeblogException("Failed to upload Media Object");
        }
    public Task <MediaObjectInfo> NewMediaObjectAsync(string blogid, string username, string password, MediaObject mediaObject)
    {
        EnsureUser(username, password);

        return(TryExecuteAsync(async() =>
        {
            // TODO: Check extension names

            var bits = Convert.FromBase64String(mediaObject.bits);

            var pFilename = _fileNameGenerator.GetFileName(mediaObject.name);
            var filename = await _blogImageStorage.InsertAsync(pFilename, bits);

            var imageUrl = $"{Helper.ResolveRootUrl(null, _blogConfig.GeneralSettings.CanonicalPrefix, true)}image/{filename}";

            var objectInfo = new MediaObjectInfo {
                url = imageUrl
            };
            return objectInfo;
        }));
    }
Beispiel #7
0
        MediaObjectInfo IMetaWeblog.NewMediaObject(string blogid,
                                                   string username, string password, MediaObject mediaObject)
        {
            if (InvalidUser(username, password))
            {
                throw new XmlRpcFaultException(INVALID_CREDENTIALS,
                                               INVALID_CREDENTIALS_MSG);
            }
            MediaObjectInfo objectInfo    = new MediaObjectInfo();
            string          mediaFileName = Path.Combine(
                AppDomain.CurrentDomain.BaseDirectory + "\\Content",
                mediaObject.name);
            string justDir = Path.GetDirectoryName(mediaFileName);

            try {
                EnsureDirectory(new DirectoryInfo(justDir));
                File.WriteAllBytes(mediaFileName, mediaObject.bits);
            }
            catch (SecurityException se) {
                throw new XmlRpcFaultException(MEDIAOBJECT_PERMISSION_FAILURE,
                                               "Permission to write " + mediaFileName + "denied. Underlying " +
                                               "error: " + se.Message);
            }
            catch (IOException ioe) {
                throw new XmlRpcFaultException(MEDIAOBJECT_IO_FAILURE,
                                               "Could not write " + mediaFileName + ". Underlying error: " +
                                               ioe.Message);
            }
            string appPath = Context.ApplicationInstance.Request.ApplicationPath;

            /* When installed in the root dir of server the appPath="/". This
             * makes the url be //Content/mediaobject.name which causes this:
             * http://Content/mediaObject.name on production. */
            if (appPath.Length > 1)
            {
                appPath += "/";
            }
            objectInfo.url = appPath + "Content/" + mediaObject.name;
            return(objectInfo);
        }
Beispiel #8
0
        public MetaWeblog.MediaObjectInfo newMediaObject(string blogid, string username, string password, MetaWeblog.MediaObject mediaObject)
        {
            if (ValidateUser(username, password))
            {
                if (mediaObject.bits != null && !string.IsNullOrEmpty(mediaObject.name))
                {
                    string fileName = mediaObject.name;

                    //Mars Edit appends '/' and this causes .NET to save the file at the root of Windows.
                    if (fileName.StartsWith("/"))
                        fileName = fileName.Substring(1);

                    int i = fileName.LastIndexOf(Path.DirectorySeparatorChar);
                    if (i != -1)
                        fileName = fileName.Substring(i + 1);

                    bool isImage = Regex.IsMatch(Path.GetExtension(mediaObject.name), ".jpg|.jpeg|.png|.gif",RegexOptions.IgnoreCase);

                    string name = isImage ?  Path.Combine(Context.Server.MapPath("~/files/media/image"), fileName) :  Path.Combine(Context.Server.MapPath("~/files/media/file"), fileName);

                    FileInfo fi = new FileInfo(name);
                    if (!fi.Directory.Exists)
                        fi.Directory.Create();

                    using (FileStream fs = new FileStream(name, FileMode.Create, FileAccess.Write, FileShare.None))
                    {
                        byte[] buffer = new byte[256*1024];
                        int bytes;

                        MemoryStream content = new MemoryStream(mediaObject.bits);

                        while ((bytes = content.Read(buffer, 0, 256*1024)) > 0)
                            fs.Write(buffer, 0, bytes);
                        fs.Close();
                    }

                    MediaObjectInfo info = new MediaObjectInfo();
                    string absolteUrl = VirtualPathUtility.ToAbsolute((isImage ? "~/files/media/image/" : "~/files/media/file/") + fileName);

                    info.url = new Macros().FullUrl(absolteUrl);
                    return info;
                }
            }
            throw new XmlRpcFaultException(0, "User does not exist");
        }