Is it possible use HttpUtils2 to upload file?

sally3599

Member
Licensed User
here is the log

Hello Erel.

It has a error message: "Request Entity Too Large".

B4X:
08-11 04:37:44.205 I/B4A     ( 1921): ** Activity (main) Resume **
08-11 04:37:44.654 I/System.out( 1931): ignoring event: mp_streambuffer
08-11 04:37:45.616 D/wpa_supplicant(  192): wpa_driver_priv_driver_cmd RSSI-APPROX len = 4096
08-11 04:37:45.625 D/wpa_supplicant(  192): wpa_driver_priv_driver_cmd MyHa2 rssi -50  len = 15, 15
08-11 04:37:45.625 D/wpa_supplicant(  192): wpa_driver_priv_driver_cmd LINKSPEED len = 4096
08-11 04:37:45.625 D/wpa_supplicant(  192): wpa_driver_priv_driver_cmd LinkSpeed 54 len = 12, 12
08-11 04:37:45.655 I/System.out( 1931): ignoring event: mp_streambuffer
08-11 04:37:46.655 I/System.out( 1931): ignoring event: mp_streambuffer
08-11 04:37:47.654 I/System.out( 1931): ignoring event: mp_streambuffer
08-11 04:37:48.624 D/wpa_supplicant(  192): wpa_driver_priv_driver_cmd RSSI-APPROX len = 4096
08-11 04:37:48.624 D/wpa_supplicant(  192): wpa_driver_priv_driver_cmd MyHa2 rssi -53  len = 15, 15
08-11 04:37:48.624 D/wpa_supplicant(  192): wpa_driver_priv_driver_cmd LINKSPEED len = 4096
08-11 04:37:48.635 D/wpa_supplicant(  192): wpa_driver_priv_driver_cmd LinkSpeed 54 len = 12, 12
08-11 04:37:48.655 I/System.out( 1931): ignoring event: mp_streambuffer
08-11 04:37:49.625 I/B4A     ( 1921): <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
08-11 04:37:49.625 I/B4A     ( 1921): <html><head>
08-11 04:37:49.625 I/B4A     ( 1921): <title>413 Request Entity Too Large</title>
08-11 04:37:49.625 I/B4A     ( 1921): </head><body>
08-11 04:37:49.625 I/B4A     ( 1921): <h1>Request Entity Too Large</h1>
08-11 04:37:49.625 I/B4A     ( 1921): The requested resource<br />/b4a/upload.php<br />
08-11 04:37:49.625 I/B4A     ( 1921): does not allow request data with GET requests, or the amount of data provided in
08-11 04:37:49.625 I/B4A     ( 1921): the request exceeds the capacity limit.
08-11 04:37:49.625 I/B4A     ( 1921): <p>Additionally, a 404 Not Found
08-11 04:37:49.625 I/B4A     ( 1921): error was encountered while trying to use an ErrorDocument to handle the request.</p>
08-11 04:37:49.625 I/B4A     ( 1921): </body></html>
08-11 04:37:49.625 I/B4A     ( 1921): JobName = JobPostName, Success = false
08-11 04:37:49.625 I/B4A     ( 1921): Error: Request Entity Too Large

Actually the file size only 2MB, and the upload_max_filesize on server is 128M,the attach is php file.

Any help will be appreciate it.
 

Attachments

  • upload.zip
    443 bytes · Views: 524
Upvote 0

sally3599

Member
Licensed User
Hello Erel.

Here is the Activity:

B4X:
'Activity module
Sub Process_Globals

End Sub

Sub Globals
    Dim etNumber As EditText
    etNumber.Initialize("etNumber")
    Dim cmdSubmit As Button
    cmdSubmit.Initialize("cmdSubmit")
    cmdSubmit.Text = "Submit"
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.AddView(etNumber, 10, 10, 100%x-20,100)
    Activity.AddView(cmdSubmit, 10, 110, 100%x-20,100)
End Sub

Sub cmdSubmit_Click
    Dim jobPost As HttpJob
    jobPost.Initialize("JobPostName",Me)
    jobPost.PostFile("http://website/b4a/upload.php",File.DirRootExternal,"1.zip")
End Sub

Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName
            Case "JobPostName"
                ToastMessageShow("Success!", True)
        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Thanks for your help...
 
Last edited:
Upvote 0

sally3599

Member
Licensed User
another error message

Is it right?
B4X:
jobPost.PostFile("http://website.com/b4a/upload.php",File.DirRootExternal,"1.zip")

it gave me another error message:
B4X:
08-12 04:12:49.198 I/B4A     ( 2269): ** Activity (main) Resume **
08-12 04:12:49.508 D/wpa_supplicant(  191): wpa_driver_priv_driver_cmd RSSI-APPROX len = 4096
08-12 04:12:49.518 D/wpa_supplicant(  191): wpa_driver_priv_driver_cmd MyHa2 rssi -53  len = 15, 15
08-12 04:12:49.518 D/wpa_supplicant(  191): wpa_driver_priv_driver_cmd LINKSPEED len = 4096
08-12 04:12:49.518 D/wpa_supplicant(  191): wpa_driver_priv_driver_cmd LinkSpeed 54 len = 12, 12
08-12 04:12:51.048 I/B4A     ( 2269): <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
08-12 04:12:51.048 I/B4A     ( 2269): <html><head>
08-12 04:12:51.048 I/B4A     ( 2269): <title>406 Not Acceptable</title>
08-12 04:12:51.048 I/B4A     ( 2269): </head><body>
08-12 04:12:51.048 I/B4A     ( 2269): <h1>Not Acceptable</h1>
08-12 04:12:51.048 I/B4A     ( 2269): <p>An appropriate representation of the requested resource /b4a/upload.php could not be found on this server.</p>
08-12 04:12:51.048 I/B4A     ( 2269): <p>Additionally, a 404 Not Found
08-12 04:12:51.048 I/B4A     ( 2269): error was encountered while trying to use an ErrorDocument to handle the request.</p>
08-12 04:12:51.048 I/B4A     ( 2269): </body></html>
08-12 04:12:51.058 I/B4A     ( 2269): JobName = JobPostName, Success = false
08-12 04:12:51.058 I/B4A     ( 2269): Error: Not Acceptable

Do you know why it always show "/b4a/upload.php", the url was cut ?
Any help will be appreciate it.
 
Upvote 0

sally3599

Member
Licensed User
the WebView1.LoadUrl can generate a file correctly on the server , but I don't know how to use HttpUtils2 to access that page.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    WebView1.Initialize("WebView1")
    Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
    If FirstTime Then
       LoadedUrl="http://website/b4a/upload.php"
    End If
End Sub

Sub Activity_Resume
    WebView1.LoadUrl(LoadedUrl)
End Sub

For PostString, I use test.php to write a file on the server:

B4X:
jobPost.PostString("http://website/b4a/test.php","number="&etNumber.Text)

the app show Success:
B4X:
08-13 03:32:18.100 I/B4A     ( 3808): JobName = JobPostName, Success = true

But actually it was fail too, nothing generate on the server!

Any help will be appreciate it.
 
Upvote 0

sally3599

Member
Licensed User
test.php & upload.php

Attach file inckluded test.php and upload.php.
They will show alert and generate a empty file in directory of upload/ if run them directly.

Any help will be appreciate it.
 

Attachments

  • test_upload.zip
    547 bytes · Views: 523
Upvote 0

sally3599

Member
Licensed User
the Download2 and PostString of HttpJob are work

Thanks Erel.
The GET and POST of HttpJob are work.
B4X:
   'Send a GET request
   job1.Download2("http://www.basic4ppc.com/print.php", _
      Array As String("first key", "first value :)", "second key", "value 2"))
   
   'Send a POST request
   job2.Initialize("Job2", Me)
   job2.PostString("http://www.basic4ppc.com/print.php", "first key=first value&key2=value2")

But for the PostFile, it still show a error "Not Acceptable" :
B4X:
jobPost.PostFile("http://website.com/upload.php",File.DirRootExternal,"1.zip")

is the php script right?
PHP:
$str = file_get_contents('php://input', 'r');

This forum can't post entire content of this script, so I upload it in the attach file.
Any help will be appreciate it.
 

Attachments

  • upload.zip
    237 bytes · Views: 385
Upvote 0

sally3599

Member
Licensed User
Were can I find the error message from google?

Thanks Erel.

So you checked my php script, is it no problem?
The PHP server configuration made by cpanel, it's a general environment.

Where can I find the error message from google about "Not Acceptable"? Would you please post a URL about this?

Any help will be appreciate it.
 
Last edited:
Upvote 0

sally3599

Member
Licensed User
it works.

Thanks Erel.

I use another cpanel server, it works now!

The reason came from Mod Seurity, because android send "Invalid character in request".
 
Last edited:
Upvote 0
U

unba1300

Guest
Hi. I'm using the following code to upload a zip file...
B4X:
job2.PostFile("http://ccotesting.site11.com/serTestUpload.php", File.DirInternal, varZipFileUp)
and I get no errors. Using the php code...
PHP:
$PostData = file_get_contents("php://input");
I can see the contents of zip file in the B4A log. But if I use php code...
PHP:
$FileName = $_GET['FileName'];
nothing is returned. What can I do in my php code to recognize the uploaded zip file and move it to the upload directory? Thanks.
 
Upvote 0
Top