Upload Slide Problem

18 views
Skip to first unread message

ulfat

unread,
Jun 23, 2009, 1:01:55 AM6/23/09
to SlideShare Developers
I had posted a query regarding Uploading files. But till now I am
unable to fix it.
I am using ASP.NET 1.1 and utility class of slideshare api in .net.
main problem is in executePostCommand which is taking string
parameters and we have to post the uploadfile control for
uploading.But I don't know how. Anyone please help with a working
example.

Regards
Ulfat

sri prasanna

unread,
Jun 23, 2009, 1:25:57 AM6/23/09
to slideshare...@googlegroups.com
Hey,

I just googled around and got this link http://www.aspupload.com/codesample.html.
But I wanna make sure one thing. Are you using "multipart/form-data' in ENCTYPE in form tag like this
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="Upload.asp">
Hope this helps.

Regards,
Sri Prasanna. K
Blog: http://sprasanna.com

Ulfat Hussain

unread,
Jun 23, 2009, 1:49:19 AM6/23/09
to slideshare...@googlegroups.com
Hi , thanks for quick reply.
I am using .NET not ASP classic.
I have a page where fileuploadcontrol has been placed.and a button yo upload file.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Button click is as follows
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
         Dim sap As New SlideShareAPI.SlideShareAPI.slideshare
        sap.initializeKeys("apikey", "secret")
        Dim bytes As Byte()

        'Get the posted file

        Dim fileDataStream As IO.Stream = slideshow_srcfile.PostedFile.InputStream

        'Get length of file
        Dim fileLength As Integer = slideshow_srcfile.PostedFile.ContentLength

        'Create a byte array with file length
        Dim fileData(fileLength) As Byte

        'Read the stream into the byte array
        fileDataStream.Read(fileData, 0, fileLength)

        'get the filename
        Dim fileTitle As String = slideshow_srcfile.Value

        'get the file type
        Dim fileType As String = slideshow_srcfile.PostedFile.ContentType

       
        sap.UploadSlide("name", fileData, fileType)

this uploadSlide function is in the dll

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
and is as follows
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  Dim parameters As String = ((("api_key=" & api_key & "&ts=") + timestamp & "&hash=") + CalculateSHA1(shared_secret + timestamp, Encoding.UTF8) & "&slideshow_title=") + slideName '& "&slideshow_srcfile=" + SlideSRC


            parameters &= "&username=username" & "&password=password"

            Dim reader As String = executeUploadCommand(parameters, slideName, type, SlideSRC)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
now executeUploadCommand is as follows
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim boundary As String = "----WhatIsTheBoundary"

            If api_key Is Nothing OrElse shared_secret Is Nothing OrElse timestamp Is Nothing Then
                Return "Keys must be initialized first"
            End If

            Dim webRequest__1 As WebRequest = WebRequest.Create("http://www.slideshare.net/api/1/upload_slideshow")
            webRequest__1.ContentType = "multipart/form-data; boundary=" & boundary
            webRequest__1.Method = "POST"
            webRequest__1.Timeout = 600000

            Dim keys As String() = parameters.Split(New Char() {"&"c})

            ' Set the body of request
            Dim sb As New StringBuilder
            sb.Append("--")
            sb.Append(boundary)
            sb.Append(vbCr & vbLf)
            For i As Integer = 0 To keys.Length - 1
                Dim param As String() = keys(i).Split(New Char() {"="c})
                sb.Append("Content-Disposition: form-data; name=""" & param(0) & """")
                sb.Append(vbCr & vbLf)
                sb.Append(vbCr & vbLf)
                sb.Append(param(1))
                sb.Append(vbCr & vbLf)
                sb.Append("--")
                sb.Append(boundary)
                sb.Append(vbCr & vbLf)
            Next
            sb.Append("Content-Disposition: form-data; name=""" & "slideshow_srcfile" & """")
            sb.Append("; filename=""" & fname & """")
            sb.Append(vbCr & vbLf)
            sb.Append("Content-Type:" & [ctype])
            sb.Append(vbCr & vbLf)
            sb.Append(vbCr & vbLf)

            Dim message As String = sb.ToString()

            Dim bytes As Byte() = Encoding.UTF8.GetBytes(message)
            Dim msgbyte As Byte() = New Byte(bytes.Length + (file.Length - 1)) {}

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

            ' Ending Boundry
            Dim sb2 As New StringBuilder
            sb2.Append("--")
            sb2.Append(boundary)
            sb2.Append("--")
            Dim message2 As String = sb2.ToString()

            Dim bytes2 As Byte() = Encoding.UTF8.GetBytes(message2)
            Dim msgbyte2 As Byte() = New Byte(bytes2.Length + (msgbyte.Length - 1)) {}

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

            Dim os As Stream = Nothing
            Try
                webRequest__1.ContentLength = msgbyte2.Length
                os = webRequest__1.GetRequestStream()
                os.Write(msgbyte2, 0, msgbyte2.Length)
            Catch ex As WebException
                Return ex.ToString()
            Finally

                If os Is Nothing = False Then
                    os.Close()
                End If
            End Try

            Try
                Dim webResponse As WebResponse = webRequest__1.GetResponse()
                If webResponse Is Nothing Then
                    Return Nothing
                End If
                Dim sr As New StreamReader(webResponse.GetResponseStream())
                Return sr.ReadToEnd().Trim()
            Catch ex As WebException
                Return ex.ToString()
            End Try
        End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
whenever i execute this. an error is returned "Invalid Extension"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

I think there is problem in executeUploadCommand.

Please review this code.and reply me.

ulfat

unread,
Jun 23, 2009, 5:23:58 AM6/23/09
to SlideShare Developers
Hi,
After debugging I have found the error.I was calling the function like
this

sap.UploadSlide("name", fileData, fileType)

here instead of passing "name"
I had to pass
myuploadcontrol.postedfile.filename
which contains the location of file .Changing this solved the problem.

Now my slides are uploaded .
but a new problem has arised .
When i upload using api and these methods,Files uploaded are not
avaliable and an "Oops" error occurs.
Any idea about this.

Regards
Ulfat Hussain

On Jun 23, 10:25 am, sri prasanna <macho...@gmail.com> wrote:
> Hey,
>
> I just googled around and got this linkhttp://www.aspupload.com/codesample.html.
> But I wanna make sure one thing. Are you using "multipart/form-data' in
> ENCTYPE in form tag like this
>  <FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="Upload.asp">
> Hope this helps.
>
> Regards,
> Sri Prasanna. K
> Blog:http://sprasanna.com
>

sri prasanna

unread,
Jun 23, 2009, 5:36:04 AM6/23/09
to slideshare...@googlegroups.com
Hey,

If you are getting "Oops" error then it means there is some problem with conversion. That is something temporary conversion problem and not api problem. You can try reuploading it will work for sure.


Regards,
Sri Prasanna. K
Blog: http://sprasanna.com



Reply all
Reply to author
Forward
0 new messages