Passing Files to Webservice (Base64 encoding)

E

Eric Elliston

I am writing an application that manages digital music files. I want to be
able to upload the MP3 files and have them passed over to the webservice as
a Base64 string, which is then decoded, and save in a secure place, away
from the Asp.net side of the application. The webservice will act as a
virtual "librarian" If anyone has any code examples, that would help. I
am using vb.net. I thought I had it working, it was passing the file over
to the service, and the services was decoding it and saving it in its proper
place, it had the correct file size and everything.....but it won't play.
Here is a code sample...I was wondering if it could have something to do
with the fact that I am not saving it as the same file name as it was when
it was uploaded...

Anyhow, here is the code.

Thank you!!!

Asp.net Application.....



Function Base64Encode(ByVal inData As String) 'accepts the path of the
uploaded mp3 file and passes it to the webservice
Dim by() As Byte
Dim FS As FileStream = File.Open(inData, FileMode.Open, FileAccess.Read)
Dim r As New BinaryReader(FS)
ReDim by(FS.Length)
Dim tBytes As Long = FS.Read(by, 0, FS.Length)
Dim Base64 As String = Convert.ToBase64String(by, 0, by.Length)

'this invokes the webservices and posts the base64 string
Dim fMan As GEQMan.GEQmanager = New GEQMan.GEQmanager
fMan.PostFile(Base64)
r .Close()
FS.Close

End Function

Here is the webservice code....

<WebMethod()> _
Public Function PostFile(ByVal b64 As string) 'accepts a base64 string
and decodes it, and saves it as an MP3 in a test directory.
Dim sr As StreamWriter
Dim sIn() As Byte = Convert.FromBase64String(b64)
sr = New StreamWriter("c:\tmp\fSavetest.mp3", False,
System.Text.Encoding.ASCII)
Dim memStream As New System.IO.MemoryStream(b64)
sr.Write(b64)

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top