-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UploadFile : worked a couple of times, and now doesn't #85
Comments
Here's the code I'm using :
|
Try grabbing the latest source from Github I think that's been fixed and
the nuget package has not been updated to the latest
Andy Brudtkuhl
youmetandy.com
…On Tue, Jun 26, 2018 at 8:27 AM, Nefastor ***@***.***> wrote:
Here's the code I'm using :
string UploadImageRPC(string FileName)
{
// Create a site configuration
WordPressSiteConfig conf = new WordPressSiteConfig();
conf.BaseUrl = "https://" + Site.Domain;
conf.BlogId = 1;
conf.Username = Site.User;
conf.Password = Site.Password;
// Now create a client
WordPressClient client = new WordPressClient(conf);
// Now use that client to upload a file :
// Start by turning the file into a Data object
Data file = new Data();
file.Name = FileName.Substring(FileName.LastIndexOf(@"") + 1); //
Eliminate the path to the file
file.Overwrite = false;
file.Type = "image/png";
// Encode the image data
Byte[] bytearray = File.ReadAllBytes(FileName); // that works !!! wait...
it only worked once :-( WTF ???
file.Bits = bytearray;
// And now upload it
UploadResult result = client.UploadFile(file);
// Return the URL to the picture
return result.Url;
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#85 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AATsrAOiAZl0nxpmADZcxlE3jv9e_TUsks5uAjbCgaJpZM4U36-B>
.
|
Thank you for the tip, Andy. I'll try that and get back to you. For information, I've been able to update a few files without changing my code, and then it started misbehaving again. I'm wondering if it may have something to do with my server. If updating the code won't work I'll contact my hosting provider. |
So I did what you suggest, and there's no difference. Just to be sure I got it right : I cloned the repo, opened the solution in Visual Studio, rebuilt it, grabbed the DLL from the output folder and copied it to the packages\WordPressSharp.1.1.0\lib\net45 in my own project, then rebuilt that. Did I miss a step ? |
Progress update : I've tried my code on a second PC that uses a different internet connection, and I got the same result. It's quite deterministic really : it stops working after I send 5 files in rapid succession. Those are PNG's between 2 and 5 KB so I don't think the size is the issue, rather I think the people who host my site might have some sort of "hacker protection" that detects those rapid uploads and prevents anything else from going through. What's annoying though is that I don't get some sort of alert... I will get in touch with them and we'll see what's what, but for what it's worth I can't find anything wrong with your code or the way I use it, and the best proof is that when it works, it works very well. |
Very much sounds like your host is blocking it based on those patterns
Andy Brudtkuhl
youmetandy.com
…On Tue, Jun 26, 2018 at 12:45 PM, Nefastor ***@***.***> wrote:
Progress update : I've tried my code on a second PC that uses a different
internet connection, and I got the same result. It's quite deterministic
really : it stops working after I send 5 files in rapid succession. Those
are PNG's between 2 and 5 KB so I don't think the size is the issue, rather
I think the people who host my site might have some sort of "hacker
protection" that detects those rapid uploads and prevents anything else
from going through. What's annoying though is that I don't get some sort of
alert... I will get in touch with them and we'll see what's what, but for
what it's worth I can't find anything wrong with your code or the way I use
it, and the best proof is that when it works, it works very well.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#85 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AATsrNBbB8t-eggQvl4YTUwGwRyIU8TSks5uAnMogaJpZM4U36-B>
.
|
Hello Andy, So yeah, the problem was my host. Their security software identified the XML-RPC file uploads as attacks designed to exploit CVE-2013-0235, a WordPress vulnerability. The details are at : https://www.cvedetails.com/cve/CVE-2013-0235/ I think we can close the issue, but maybe it's worth mentioning somewhere that this is a scenario that can happen with some hosts. Anyway, thanks for your time, and for WordPressSharp ! Even though I'll try to upload files to WordPress by some other means ASAP, it's nice to have something that works and that's easy to work with. |
Hi,
I'm attempting to upload images to a WordPress install using the WordPressClient.UploadFile method. The code I use is very straightforward and it worked a couple of time, resulting in proper entries in the site's media library. Then I went out for lunch, tried to upload more files, and it didn't work. I tried to upload the first file again, it didn't work either.
I put a breakpoint at the UploadFile call, hoping to have a look at its return value. However, when when I hit F10 (Step Over) I ended up in the calling method's calling method, bypassing other breakpoints along the way.
So I get a piece of code that worked once, and now doesn't, and I can't get a clue as to what's wrong. I'm not excluding the possibility of a server-side issue (it's the first time I try to upload to a site programmatically) but even then I'd expect UploadFile to behave more "normally" when debugging. Can you tell me what's going on ?
By the way, I've installed WordPressSharp from NuGet. I'm using Visual Studio 2017. Network connectivity is OK, and I own the website to which I'm trying to post. Here's my method for uploading an image file (those are all PNG's by the way)
(oops... I can't seem to find a way to paste my code so it'll be readable. I'll try again later.)
The text was updated successfully, but these errors were encountered: