It seems php file uploads are faster than ftp

Mashiane

Expert
Licensed User
Longtime User
Mmmmhhhh

Well, for some reason, perhaps my server configuration for the clients app was the cause, Apple just didnt pass the app due to some error that I previously posted here in the forum. But then again, the android version of the app works perfectly with ftp (sooner to find out, a little slower)

Finally, apple approved the app, available here. After some many changes here and there to meet their requirements. This ftp upload error, a 503 thing of some sort in their ipv6 network made me to try an option I found here, php file uploads.

B4X:
<?php
if (isset($_REQUEST['action'])){$action=trim($_REQUEST['action']);} else {$action="";}
if (isset($_REQUEST['filepath'])){$filepath=trim($_REQUEST['filepath']);} else {$filepath="";}

switch ($action)
{
    case "upload":
        $filepath = $filepath . basename( $_FILES['processfile']['name']);
        if(move_uploaded_file($_FILES['processfile']['tmp_name'], $filepath)) {
                echo "success";
            } else{
                echo "fail";
            }
}
?>

So I call this UploadFilePhp... and trap the outcome with the JobDone event..

B4X:
dbAction.Initialize
    dbAction.Put("action", "upload")
    dbAction.Put("filepath", "")
    modMashiane.UploadFilePhp(Me, dbAction, "", iPath, "upload", "uploadfile.php", "upload")

B4X:
Sub UploadFilePhp(frm As Object, pQuery As Map, dir As String, fil As String, JobName As String, phpFile As String, phpTag As String)
    Dim job As HttpJob
    Dim fd As MultipartFileData
    ' initialize the job
    job.Initialize(JobName, frm)
    job.Tag = phpTag
    ' initialize the mulipart
    fd.Initialize
    fd.KeyName = "processfile"
    fd.Dir = dir
    fd.FileName = fil
    ' determine the contenttype
    If fil.EndsWith(".png") = True Then fd.ContentType = "image/png"
    If fil.EndsWith(".jpg") = True Then fd.ContentType = "image/jpeg"
    If fil.EndsWith(".jpeg") = True Then fd.ContentType = "image/jpeg"
    If fil.EndsWith(".json") = True Then fd.ContentType = "application/json"
    ' execute the script to upload the file
    job.PostMultipart(Starter.phpPath & phpFile, pQuery, Array(fd))
End Sub

and JobDone...

B4X:
Sub JobDone (Job As HttpJob)
    modMashiane.HideSpinner(spinner)
    EnableDisable(True)
    If Job.Success = True Then
        Select Job.JobName
        Case "upload"
            JobTag = Job.getstring
            Job.release
            Select Case JobTag
            Case "success"
                    <Do WhatEver>
            Case "fail"
                    <Scream>
            End Select
         End Select
    Else
        <Scream>
    End If
End Sub

I remove my ftp upload code, run some tests and I am happy, the client uploads the new ipa to the apple store, whalla! approved.

Couple of hours later....

Client: The php uploads you did are bullet speed, please clone for the android version..
Me: Really?

Now updating the Android version of the app.

A lesson learnt but still don't understand why Apple were having the network error with their ipv6 wifi network, but then again, the "it works on my machine syndrome" with coders is something I try and avoid at all costs.Strange because the net libraries were updated

Just to regress, one of the things I had to port in this app was the viewpager. Without a sliding panel thingy in b4i i had to literally write a customview, a trial and error exercise which I eventually figured out and the reason it didnt work properly at first was the very important "Resize" event.

I have learnt that as much as these two frameworks look the same, the apps dont behave the same, you need to be more aware of b4i functionalities and how the whole beast works to crack things and porting apps is not as simple as ABC, esp when they are complex.

Ta!
 

sorex

Expert
Licensed User
Longtime User
http is the way to go as it's open on every network unlike FTP/SFTP.

With broadband the speed difference is gone compared to the 90s where using FTP was faster, more stable and supported resuming downloads.

it's good that you passed the review team, they can be picky sometimes. :)
 
Top