Hi there,
I’m trying to upload a file to a server using Corona. I’m using mime.b64 encoding, based on the example I saw here:
http://developer.coronalabs.com/code/upload-binary-corona-php-script
Instead of passing the file to a php script I’m using ASP.Net (VB.Net).
The problem I have is that I get the following error back from my VB.Net script, which looks like the encoding Corona-side has a problem and isn’t being performed correctly. The .Net script runs fine on its own.
_ “Invalid length for a Base-64 char array or string” _
My code is as follows:
LUA upload function:
function uploadBinary ( filename, url, onComplete ) local mime = require "mime" local path = system.pathForFile( filename ) local fileHandle = io.open( path, "rb" ) if fileHandle then local params = { body = "png=" .. mime.b64( fileHandle:read( "\*a" )) .. "&filename="..filename } params.progress = "download"; io.close( fileHandle ) network.request( url, "POST", networkListener, params) end end -- Call the upload binary function uploadBinary ( "image.png", "http://myDomain.com/receiveFile.aspx")
LUA listener
function networkListener( event ) local phase = event.phase; if (phase == "ended") then if ( event.isError ) then print( "Network error!") else print ( "RESPONSE: " ..event.response ) end end end
ASP.Net script to save file to server
Partial Class receiveFile Inherits System.Web.UI.Page Dim m\_strImageName As String Dim m\_strPNGBinary As String Public m\_response As String Protected Sub Page\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load m\_strImageName = Request("filename") 'file name m\_strPNGBinary = Request("png") 'binary image details If len(m\_strPNGBinary) \> 0 Then Dim saveToFolder As String = "C:\inetpub\wwwroot\myDomain\http\" + m\_strImageName Dim b() As Byte = Convert.FromBase64String(m\_strPNGBinary) If File.Exists(saveToFolder) Then File.Delete(saveToFolder) End If File.WriteAllBytes(saveToFolder, b) m\_response = "err=0" Else m\_response = "err=1" End if End Sub End Class
If anyone has any idea why I’m getting this error message back I’d be really grateful for any input. I’m totally stuck on this one.
_ “Invalid length for a Base-64 char array or string” _
I have tried changing from mime.b64 to use other methods such as those shown in this thread:
http://forums.coronalabs.com/topic/24714-fyi-base64-decode-and-encode-in-corona/
…and this one:
http://developer.coronalabs.com/code/how-upload-image-server-multipartform-data
But I get exactly the same error whatever I try.
Thanks,
Ian