I have some problems about "SlideShare API - slide_src parameter" in ASP.Net, C#

123 views
Skip to first unread message

Blumpy.tr

unread,
Dec 28, 2008, 1:34:46 PM12/28/08
to SlideShare Developers
Hey all,

I wrote a function to upload slides. my code is this:


public static string uploadSlideShow(string title, string description,
string tags, string slide_src)
{
initializeKeys();
string url = "http://www.slideshare.net/api/1/
upload_slideshow";

string parameters =
// Set the required parameters
"api_key=" + api_key +
"&ts=" + timestamp +
"&hash=" + CalculateSHA1(shared_secret + timestamp,
Encoding.UTF8) +
"&username=" + user +
"&password=" + pass +
"&slideshow_title=" + title +
"&slideshow_srcfile=" + slide_src +

// Set the optional parameters
"&slideshow_description=" + description +
"&slideshow_tags=" + tags +
"&make_src_public=" + "N";

// Set the required parameter
//"&slideshow_srcfile=";

return executePostCommand(url, parameters);
}

i called this function like :

string result = uploadSlideShow("test","test","test","test");

the return value of this was "6 Slideshow file isn't a source object".

in slideshare developer page, there is a DotNetUtil.zip file. i used
the executePostCommand in this.

you know that the function named executePostCommand is taking 2
parameter. and they are "string uri, string params". so how can i send
"slideshow_srcfile" parameter in a string?

i know my problem is slideshow_srcfile parameter. what should i send
for this?

Thanks all of you
Best wishes,
Blumpy.tr

Gee Chuang

unread,
Dec 29, 2008, 1:06:04 PM12/29/08
to SlideShare Developers

Hi there,

The slideshow_srcfile parameter should be the actual file, not just a
string representing the path to the file on your local machine.

You'll need to send a multipart/form-data POST request.

Thanks
Gee

Blumpy.tr

unread,
Dec 30, 2008, 5:22:33 AM12/30/08
to SlideShare Developers

Hi Gee,

Firstly, thanks for your reply.

I know that i have to send "multipart/form-data POST request". But
there is an official code sample "Microsoft .NET (C#) - DotNetUtil".
And it contains a function to execute a post command.

so

Can we say that "this function is not ok for uploading slides?"

And should i write my own function to uploading?

Thank you so much,
Blumpy.tr

Gee Chuang

unread,
Dec 30, 2008, 1:18:02 PM12/30/08
to SlideShare Developers

Hi there,

Just took a look at the execute post command code. Unfortunately it
doesn't look like the function as-is will support file upload.

The only method using the post is getEmbedCode, and the values it
passes are all string values

Thanks
Gee

Blumpy.tr

unread,
Jan 1, 2009, 5:34:44 PM1/1/09
to SlideShare Developers
Hi,

OK Gee, and thank you so much.

Thanks,
Blumpy.tr

Blumpy.tr

unread,
Jan 2, 2009, 8:44:12 AM1/2/09
to SlideShare Developers
Hi again,

I tried to write my upload function but i guess i couldn do this.

The codes are here:

private static string executeUploadCommand(string parameters, string
fname, string ctype, byte[] file)
{
string boundary = "---WhatIsTheBoundary---";

if (api_key == null || shared_secret == null || timestamp
== null)
return "Keys must be initialized first";

WebRequest webRequest = WebRequest.Create("http://
www.slideshare.net/api/1/upload_slideshow");
webRequest.ContentType = "multipart/form-data; boundary="
+ boundary;
webRequest.Method = "POST";

string[] keys = parameters.Split(new char[] { '&' });

// Set the body of request
string message = "--" + boundary + "\r\n";
for (int i = 0; i < keys.Length; i++)
{
string[] param = keys[i].Split(new char[] { '=' });
message += "Content-Disposition: form-data; name=\"" +
param[0] + "\"";
message += "\r\n";
message += param[1];
message += "\r\n";
message += "--" + boundary + "\r\n";
}

message += "Content-Disposition: form-data; name=\"" +
"slideshow_srcfile" + "\"";
message += "; filename=\"" + fname + "\"";
message += "\r\n";
message += "Content-Type:" + ctype;
message += "\r\n";

byte[] bytes = Encoding.ASCII.GetBytes(message);
byte[] msgbyte = new byte[bytes.Length + file.Length];

Array.Copy(bytes, msgbyte, bytes.Length);
Array.Copy(file, 0, msgbyte, bytes.Length, file.Length);

Stream os = null;
try
{
webRequest.ContentLength = msgbyte.Length;
os = webRequest.GetRequestStream();
os.Write(msgbyte, 0, msgbyte.Length);
}
catch (WebException ex)
{
return ex.ToString();
}

finally
{
if (os != null)
{
os.Close();
}
}

try
{
WebResponse webResponse = webRequest.GetResponse();
if (webResponse == null)
{ return null; }
StreamReader sr = new StreamReader
(webResponse.GetResponseStream());
return sr.ReadToEnd().Trim();
}
catch (WebException ex)
{
return ex.ToString();
}
}

This function returns :

" Status: 500 Internal Server Error Content-Type: text/html
500 Internal Server Error "

When i debug the code, everything seems ok. i cant resolve the
problem.

Thanks,
Blumpy.tr

Blumpy.tr

unread,
Jan 19, 2009, 8:17:34 AM1/19/09
to SlideShare Developers
Anoyone can help ?

Thx

On Jan 2, 3:44 pm, "Blumpy.tr" <blumpy...@gmail.com> wrote:
> Hi again,
>
> I tried to write my upload function but i guess i couldn do this.
>
> The codes are here:
>
> private static string executeUploadCommand(string parameters, string
> fname, string ctype, byte[] file)
>         {
>             string boundary = "---WhatIsTheBoundary---";
>
>             if (api_key == null || shared_secret == null || timestamp
> == null)
>                 return "Keys must be initialized first";
>
>             WebRequest webRequest = WebRequest.Create("http://www.slideshare.net/api/1/upload_slideshow");

Gee Chuang

unread,
Jan 27, 2009, 3:20:36 PM1/27/09
to SlideShare Developers

Hi there,

From the other thread it sounds like you've got uploads to work?

Let me know if you're still having problems.

Thanks
Gee

Blumpy.tr

unread,
Jan 29, 2009, 4:03:21 AM1/29/09
to SlideShare Developers
Hi Gee,

Thank you for your interest.

I resolved my problem and i can upload slides now.

This is my uploadFunction:

private static string executeUploadCommand(string parameters, string
fname, string ctype, byte[] file)
{
string boundary = "----WhatIsTheBoundary";

if (api_key == null || shared_secret == null || timestamp
== null)
return "Keys must be initialized first";

WebRequest webRequest = WebRequest.Create("http://
www.slideshare.net/api/1/upload_slideshow");
webRequest.ContentType = "multipart/form-data; boundary="
+ boundary;
webRequest.Method = "POST";
webRequest.Timeout = 60000;

string[] keys = parameters.Split(new char[] { '&' });

// Set the body of request
StringBuilder sb = new StringBuilder();
sb.Append("--");
sb.Append(boundary);
sb.Append("\r\n");
for (int i = 0; i < keys.Length; i++)
{
string[] param = keys[i].Split(new char[] { '=' });
sb.Append("Content-Disposition: form-data; name=\"" +
param[0] + "\"");
sb.Append("\r\n");
sb.Append("\r\n");
sb.Append(param[1]);
sb.Append("\r\n");
sb.Append("--");
sb.Append(boundary);
sb.Append("\r\n");
}
sb.Append("Content-Disposition: form-data; name=\"" +
"slideshow_srcfile" + "\"");
sb.Append("; filename=\"" + fname + "\"");
sb.Append("\r\n");
sb.Append("Content-Type:" + ctype);
sb.Append("\r\n");
sb.Append("\r\n");

string message = sb.ToString();

byte[] bytes = Encoding.UTF8.GetBytes(message);
byte[] msgbyte = new byte[bytes.Length + file.Length];

Array.Copy(bytes, msgbyte, bytes.Length);
Array.Copy(file, 0, msgbyte, bytes.Length, file.Length);

// Ending Boundry
StringBuilder sb2 = new StringBuilder();
sb2.Append("--");
sb2.Append(boundary);
sb2.Append("--");
string message2 = sb2.ToString();

byte[] bytes2 = Encoding.UTF8.GetBytes(message2);
byte[] msgbyte2 = new byte[bytes2.Length +
msgbyte.Length];

Array.Copy(msgbyte, msgbyte2, msgbyte.Length);
Array.Copy(bytes2, 0, msgbyte2, msgbyte.Length,
bytes2.Length);

Stream os = null;
try
{
webRequest.ContentLength = msgbyte2.Length;
os = webRequest.GetRequestStream();
os.Write(msgbyte2, 0, msgbyte2.Length);
}
catch (WebException ex)
{
return ex.ToString();
}

finally
{
if (os != null)
{
os.Close();
}
}

try
{
WebResponse webResponse = webRequest.GetResponse();
if (webResponse == null)
{ return null; }
StreamReader sr = new StreamReader
(webResponse.GetResponseStream());
return sr.ReadToEnd().Trim();
}
catch (WebException ex)
{
return ex.ToString();
}
}

I know that comments are missing But it may help other friends.

Its a sample for uploading slides to slideshare via api v1.0

Thank you and your developer team.

Best,
Blumpy.tr

Gee Chuang

unread,
Jan 29, 2009, 12:54:44 PM1/29/09
to SlideShare Developers

Hi there,

Sorry we couldn't help you sooner, but I'm glad you got everything
working! =)

Gee



On Jan 29, 1:03 am, "Blumpy.tr" <blumpy...@gmail.com> wrote:
> Hi Gee,
>
> Thank you for your interest.
>
> I resolved my problem and i can upload slides now.
>
> This is my uploadFunction:
>
> private static string executeUploadCommand(string parameters, string
> fname, string ctype, byte[] file)
>         {
>             string boundary = "----WhatIsTheBoundary";
>
>             if (api_key == null || shared_secret == null || timestamp
> == null)
>                 return "Keys must be initialized first";
>
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages