wp-net / WordPressPCL

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

Problem with CreateMedia (create but in invalid format) #341

Open edmilsonlani opened 1 year ago

edmilsonlani commented 1 year ago

I'm testing the library and I managed to create a post correctly, but when I try to create a media, it doesn't work correctly.

It uploads the image to the folder correctly, but it has a different size and a non-image format.

I tested a few methods and they all worked the same way.

if (await client.Auth.IsValidJWTokenAsync()) { //Stream s = new FileStream(@"C:\Temp\erro_tela.png", FileMode.Open, FileAccess.Read, FileShare.Read); Stream s = File.OpenRead(@"C:\Temp\erro_tela.png"); var createdMedia = await client.Media.CreateAsync(s, "erro_tela.png"); //var createdMedia = await client.Media.CreateAsync(@"C:\Temp\erro_tela.png", "erro_tela.png"); Console.WriteLine(createdMedia.MimeType); Console.WriteLine(createdMedia.SourceUrl); }

This is an image

simonhammes commented 3 months ago

The following snippet worked for me:

var fs = File.Open("PNG_Test.png", FileMode.Open);
var media = await client.Media.CreateAsync(fs, "PNG_Test.png");

The file is visible in the media library and has the correct size.

This is an image

This returns a 403