wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
337 stars 129 forks source link

MediaItem Alt,Description,Title Not Working #217

Open lucaswhob opened 4 years ago

lucaswhob commented 4 years ago

Hello My Friends I Use Your Library Latest Version I Use MediaItem Upload Image Is Ok And Very Good But Property Of MediaItem SuchAs : Alt,Description,Title After Upload I Go To Wordpress Doshboard And Media Menu Image Is Uploaded Ok But Alt and Description and Title is Empty Screen Shot Of My Code MyCodeScreenShot

lucaswhob commented 4 years ago

Please Hep Me My Friends . Thx . I Am Waiting For Help You .

lucaswhob commented 4 years ago

discontinued???

ThomasPe commented 4 years ago

This library is not discontinued, but maintained by volunteers that might not be able to fix your issues within 24h on a weekend.

lucaswhob commented 4 years ago

ok . thank you . Understand My Problem ?

DustyTools commented 3 years ago

That code isn't going to work because you are setting title\description on a local object and not sending it to WP. However, I can't get Update to work for the same scenario:

                MediaItem mediaItem = await client.Media.Create(file.FullName, file.Name);

                mediaItem.Description = new Description { Raw = file.Name };
                mediaItem.Title = new Title { Raw = file.Name };
                mediaItem.Caption = new Caption { Raw = file.Name };

                await client.Media.Update(mediaItem);

The last line throws an exception:

WPUnexpectedException: Server returned HTTP status NotAcceptable An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.

ThomasPe commented 3 years ago

This worked fine for me:

            var path = Directory.GetCurrentDirectory() + "/Assets/cat.jpg";
            Stream s = File.OpenRead(path);
            var mediaItem = await _clientAuth.Media.Create(s, "cat.jpg");

            mediaItem.Description = new Description { Raw = "Cat Description" };
            mediaItem.Title = new Title { Raw = "Cat Title" };
            mediaItem.Caption = new Caption { Raw = "Cat Caption" };

            var updatedItem = await _clientAuth.Media.Update(mediaItem);
            Assert.AreEqual(mediaItem.Title.Raw, updatedItem.Title.Raw);