Skip to content
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

How to upload an image using joeblogs on wordpress blog? #28

Open
Shahid20 opened this issue Jul 9, 2013 · 17 comments
Open

How to upload an image using joeblogs on wordpress blog? #28

Shahid20 opened this issue Jul 9, 2013 · 17 comments

Comments

@Shahid20
Copy link

Shahid20 commented Jul 9, 2013

I am new to joeblogs wordpress remote publishing liberary and trying to upload an image with some post to my wordpress blog! Any code snippet to upload an image?

I have tried that string:

wrapper.UploadFile(@"C:\Users\Thomas janes\Pictures\qw.JPG","ERD Diagram",true,"image/jpeg");
but it returned me an exception saying that Server returned a fault exception: [500] Could not write file wpid-ERD-Diagram (Invalid file type). Whta does this mean and why is it occurring?

@alexjamesbrown
Copy link
Owner

You need to upload a byte[]
You're uploading a string of "C:\Users\Thomas janes\Pictures\qw.JPG"

@Shahid20
Copy link
Author

Shahid20 commented Jul 9, 2013

You mean that i should convert the filepath type to byte[] rather than String or What? Please give me an example?

@alexjamesbrown
Copy link
Owner

Yes,
But it seems that it should be.

Can you use Fiddler and find out what is going over the wire?

I suspect it's an issue like this:
http://wordpress.org/support/topic/error-could-not-write-file-wpid-m-invalid-file-type

In which case it's a bug in the library

@Shahid20
Copy link
Author

Shahid20 commented Jul 9, 2013

Sorry Sir, i read the post but i didn't get what actually is to be done! I reckon there is a need to amend sort of data type in your liberary or what? Please let me know what other solution i can try?

@alexjamesbrown
Copy link
Owner

Use fiddler
Find out what is actually being sent to the server

@Shahid20
Copy link
Author

Shahid20 commented Jul 9, 2013

Ok Sir, i look into it!

@Shahid20
Copy link
Author

Shahid20 commented Jul 9, 2013

Content-Length: 33547
Content-Type: text/xml

And fault message is being sent as response from the server!

@Shahid20
Copy link
Author

Shahid20 commented Jul 9, 2013

What else should i try? I mean could you provide your snippet to upload an image so that i could try!

@alexjamesbrown
Copy link
Owner

No, look at the actual content of the message being sent. The body
On 9 Jul 2013 12:17, "Shahid Sultan Minhas" [email protected]
wrote:

Content-Length: 33547
Content-Type: text/xml

And fault message is being sent as response from the server!


Reply to this email directly or view it on GitHubhttps://github.com//issues/28#issuecomment-20667451
.

@Shahid20
Copy link
Author

Shahid20 commented Jul 9, 2013

Yes i checked the body in xml view,its actually sending the image with sort of tags and there i could see a tag like base64 and sort of numerical code there! I am new to fiddler so probably i can't be telling you explicitly what you want to know about! But please if you could show me a method of uploading an image, would then certainly be appreciated!
Thanks Sir!

@alexjamesbrown
Copy link
Owner

can you copy paste exactly what is in the body onto here, i'll take a look

On 9 July 2013 14:46, Shahid Sultan Minhas [email protected] wrote:

Yes i checked the body in xml view,its actually sending the image with
sort of tags and there i could see a tag like base64 and sort of numerical
code there! I am new to fiddler so probably i can't be telling you
explicitly what you want to know about! But please if you could show me a
method of uploading an image, would then certainly be appreciated!
Thanks Sir!


Reply to this email directly or view it on GitHubhttps://github.com//issues/28#issuecomment-20674614
.

@Shahid20
Copy link
Author

Shahid20 commented Jul 9, 2013

Text view of the packet!

faultCode 500 faultString Could not write file wpid-ERD-Diagram (Invalid file type) Or tell me how can i get to content of packet if you have any aquaintance with fiddler? I mean when i click on a packet, there you can see many options on the right of window where acc. to me, i am clicking on inspector tab and there you can see lot many other options like which view you want to see like xml, json,text view etc!

By far, i have converted the String to byte via this code of mine as:
static byte[] GetBytes(string str)
{
byte[] bytes = new byte[str.Length * sizeof(char)];
System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
return bytes;
}
but when i atart adding parameters to method as:
String pic = @"C:\Users\M.Shahid.Sultan\Pictures\qw.JPG"; // path of image
byte[] newpic = GetBytes(pic); // method to convert String to byte array.

wrapper.UploadFile(newpic, "ERD Diagram", true, "image/jpg"); // method referring your liberary to upload an image.
So it gives me error that first of the parameter in uploadFile method is not byte array(as you said it must be rather than String), so what should i need to change then in your liberary or what else?

@Shahid20
Copy link
Author

Shahid20 commented Jul 9, 2013

wp1
wp2
wp3

@alexjamesbrown
Copy link
Owner

Looks ok to me...
I don't know what's wrong, and unfortunately I have no time immediately to
have a look

Will have to leave the issue open for when I get time.
It's open source, so feel free to take a look yoursel

On 9 July 2013 15:30, Shahid Sultan Minhas [email protected] wrote:

[image: wp1]https://f.cloud.github.com/assets/4085893/768623/e34b013c-e8a3-11e2-8175-51909e900541.JPG
[image: wp2]https://f.cloud.github.com/assets/4085893/768626/eeb94326-e8a3-11e2-8621-91a622e60b50.JPG
[image: wp3]https://f.cloud.github.com/assets/4085893/768632/03747fce-e8a4-11e2-842f-7d49a83e53b9.JPG


Reply to this email directly or view it on GitHubhttps://github.com//issues/28#issuecomment-20677698
.

@caffedrine
Copy link

I think I know what the problem is. You have to convert IMAGE to byte arry, not image path.
You have there a simple snnipet:

        var wp = new WordPressWrapper(link + "/xmlrpc.php", username, password);
        byte[] imageData = System.IO.File.ReadAllBytes("image.png");
        var image = wp.NewMediaObject(new MediaObject { Bits = imageData, Name = "Plane.jpg", Type = "image/jpeg" });

This will work for you. :)

@CMHouse
Copy link

CMHouse commented Aug 5, 2014

Shahid,
Your code should be like this:
wrapper.UploadFile(@"C:\Users\Thomas janes\Pictures\qw.JPG","ERD-Diagram.jpg",true,"image/jpeg");

You were missing the file extension for the name of the file. It's asking for uploaded filename, not image title.

Hope this helps

@alexjamesbrown
Copy link
Owner

@Shahid20 - did @CMHouse suggestion work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants