Android Question Strange Multipart request failure

jazzzzzzz

Active Member
Licensed User
Longtime User
I have to upload a image file to a server,I have used okhttp multipart upload request to send the request,I have tested the upload in lan using php server and it works perfectly in lan.

But when the php code is hosted in web it does not work.It gives this error in the app

B4X:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>501 Method Not Implemented</title>
</head><body>
<h1>Method Not Implemented</h1>
<p>GET to /photo_admin/mobile_api.php not supported.<br />
</p>
<p>Additionally, a 501 Method Not Implemented
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
Method Not Implemented

So I thought there is some server configuration issue and tested the same request using postman in my laptop and the file was uploaded perfectly..I Am totally confused why this is not working in App in web (but works on lan)

B4X:
<p>GET to /photo_admin/mobile_api.php not supported.<br />

But this line here shows its a get request..but multipartpost is a post request Why this happens...!

Any idea or suggestions>?
 

jazzzzzzz

Active Member
Licensed User
Longtime User
It returns success here. Though move_uploaded_file returns False so it doesn't really copy the file. It is probably a permission issue here.

Did you download the sample b4a app run it in your device?
I dont think you run the project and returned success message in the device..If you get success message then the uploaded file will be available in http://www.arunneeraj.com/uploads/

Now only my project zip is there..Nothing More..!

Php file upload code is working good..You can test that in here: http://www.arunneeraj.com/upload_file
select choose file from above link and upload any file and see the file in http://www.arunneeraj.com/uploads/
from that its clear that there is no permission issue.

This is the html code that does the uploading.And the file upload works good,But same upload does not work in B4A

B4X:
<html>
<body>

<form action="http://www.arunneeraj.com/upload_demo.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="file" id="upload">
   
   
    <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>


Why are you using PHP? You can easily implement it in B4J.

Am creating app for already created server that is in php,So I cant change the whole thing into B4J
 
Upvote 0

jazzzzzzz

Active Member
Licensed User
Longtime User
I've tested it on my server.
In my server follwing are working
postman,iOS Swift3 sample code,html form submit ,In all these file are uploaded.But not in b4a.

if its my server issue then how postman and all works..!
 
Upvote 0

jazzzzzzz

Active Member
Licensed User
Longtime User
I don't know! You can download OkHttpUtils2 source code! And see the exact message created by HttpJob.PostMultiPart!

Compare it to the message created by postman!

Thanks for the clue..For the first time ever I looked into okhttputilis code.
I just commented

B4X:
req.SetContentEncoding("UTF8")

in PostMultipart and now File uploaded...!!!!!

Do you have any idea why??
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…