B4J Question CSV upload using ABMFileInput

codie01

Active Member
Licensed User
Longtime User
Hi All,

I am trying to read up a csv file. Works fine running on winapp running localhost. However when I move it to my VPS, obviously it can not find the file on my VPS as it is local.

As I see it, I can upload the file to the server first or can i Change my code in someway to see the file on my computer from the server.

I have attached the code. Thanks in advance.

Phil the ABMRockster, ABMaterial rocks and Alian is a seriously good coder.....

B4X:
Sub section0ainp1_Changed(value As String)
    Dim myTabs As ABMTabs = page.Component("mypageTab1")
    Dim myContainer1 As ABMContainer = myTabs.GetTabPage("TAB1")
    Dim myContainer2 As ABMContainer = myContainer1.Component("tab1Right")
    Dim myContainer3 As ABMContainer = myContainer2.Component("section0a")
    Dim inp1 As ABMFileInput  = myContainer3.Component("section0ainp1")

    Dim myFile As String = inp1.GetFileName

    Dim su As StringUtils
    ' header
    Dim myTransaction As String = DateTime.Now
    Dim mySalesdate As String
    Dim mySalesTime As String = DateTime.Time(DateTime.Now)
    Dim mySalesamount As Double = 0
    Dim myPayoutamount As Double = 0
    Dim myFeeamount As Double = 0
    Dim myLayaway As Double = 0
    Dim myTaxAmount As Double = 0
    Dim mySalesStatus As String = "UNCHECKED"
    Dim myUser As String = ABMShared.myUsername

    Dim sql1 As SQL
    sql1.Initialize2("com.mysql.jdbc.Driver", "jdbc:mysql://" & ABMShared.myServerAddress & "/" & ABMShared.myServerDatabase, ABMShared.myServerUsername, ABMShared.myServerPassword)

    Dim lst1 As List
    lst1 = su.LoadCSV("c:\CSV", myFile , ",") '<<<<------------------------------- here is the issue
    For i = 2 To lst1.Size - 1
        Dim sColumn() As String
        sColumn = lst1.Get(i)
        'calculate headers ---------------------------------------
        If sColumn(3) = "Fee" Then
            mySalesamount = mySalesamount + sColumn(11).SubString(1)
            myFeeamount = myFeeamount + sColumn(11).SubString(1)
            Else
            mySalesamount = mySalesamount + sColumn(11).SubString(1)
        End If
        myTaxAmount = myTaxAmount + sColumn(12).SubString(1)
        'get items information -----------------------------------
        mySalesdate = ABMShared.setdate
        mySalesTime = sColumn(1)
        Dim myTime As String = sColumn(1)
        Dim myCatagory As String = sColumn(3)
        Dim myTypecode As String = sColumn(4)
        Dim myTypename As String = sColumn(4)
        Dim myqty As Int = sColumn(5)
        Dim myGross As Double = sColumn(9).SubString(1)
        Dim myNet As Double = sColumn(11).SubString(1)
        Dim myDiscount As Double = sColumn(10).SubString(1)
        Dim myTax As Double = sColumn(12).SubString(1)
        Dim myContractNumber As String = sColumn(16)
        Dim myContractName As String = "ERROR"
        Dim myStorecode As String = sColumn(19)
        Dim myStorename As String = "ERROR"
        Dim myItemstatus As String = "ERROR"
        sql1.ExecNonQuery2("INSERT INTO salesitems VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Array As Object(myTransaction,mySalesdate,myTime,myCatagory,myTypecode,myTypename,myqty,myGross,myNet,myDiscount,myTax,myContractNumber,myContractName,myStorecode,myStorename,myItemstatus))
    Next
End Sub
 

codie01

Active Member
Licensed User
Longtime User
Hi Erel, thanks for your answer, you work very hard. I do not know how to uploaded it, are you able to point me at some code.

I would like to do this programatically from within my website.

Thanks Phil
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
I think you are almost there, just no doing the upload:

in class_globals
B4X:
Public DownloadFolder As String = "/www/" & ABMShared.AppName & "/uploads/" ' or wherever you want to put the files
Public DownloadMaxSize As String = 100*1024

In WebSocket_Connected (at the end)
B4X:
' this page uses uploads, so needs some settings   
   ws.Session.SetAttribute("abmcallback", Me)   
   ws.Session.SetAttribute("abmdownloadfolder", DownloadFolder)
   ws.Session.SetAttribute("abmmaxsize", DownloadMaxSize)

In WebSocket_Disconnected
B4X:
Try
     ws.Session.RemoveAttribute("abmcallback")   
     ws.Session.RemoveAttribute("abmdownloadfolder")
     ws.Session.RemoveAttribute("abmmaxsize")
Catch
     Log(LastException.Message)
End Try

B4X:
Sub section0ainp1_Changed(value As String)
   Log("value : " & value)
   Dim inp1 As ABMFileInput  = page.Component("inp1")
   inp1.UploadToServer 'Here the file is uploading
End Sub

Sub Page_FileUploaded(FileName As String, success As Boolean)   
   Dim inp1 As ABMFileInput  = page.Component("inp1")
   inp1.Clear
   Log(FileName & " = " & success)
   myToastId = myToastId + 1   
   page.ShowToast("toast" & myToastId, "toastred", "Uploading " & FileName & ": Success = " & success, 3000, False)
   page.ws.Flush 'IMPORTANT

   ' do your stuff
  Dim myTabs As ABMTabs = page.Component("mypageTab1")
  ... 
End Sub
 
Upvote 0

codie01

Active Member
Licensed User
Longtime User
Hi Erel, thanks for your answer, you work very hard. I do not know how to uploaded it, are you able to point me at some code.

I would like to do this programatically from within my website.

Thanks Phil

Thanks Alian, And Just as a side note ABMaterial has gone well beyond awesome. With you and Erel we are really well served and very lucky.
 
Upvote 0
Top