Android Question Send file to server using httputlis2 postfile

Similar threads

B4A Question httputlis2 post broblem
B4A Question Download image with httputlis2
B4A Code Snippet [B4X] Bytes To File
B4A Question httputlis
B4A Code Snippet Upload files with WebView

Devv

Active Member
Licensed User
Hello guys i'am trying to send a file to my server using php
i tried the following

B4X:
<?php
   $FileName = $_GET['FileName'];

   if (!$FileName)
      $FileName = "FileName";

   if (strstr($FileName,"php"))
      return;

   $PostData = file_get_contents("php://input");

   $File = fopen($FileName,"wb");

   fwrite($File, $PostData);
   fclose($File);

   echo "ACK";
?>
the following code is working but i'am always getting the file names as "FileName"

WHY php is not recognizing the file name ??
can i send the file name with the file as an extra parameter ?

PS: i'am using httputlis2 post file to send it to the php
 

Devv

Active Member
Licensed User
Cause you dont give a filename with a postfile request.
You need to use a multipartpost to give a file AND a (or even more) value with one postrequest.
See my signature for a Example
thanks for fast replay DonManfred
the files i'am working with is less than 50 KB.
sorry for this silly question but i'am a noob
multipartpost: does mean sending the file part after part each part as one http post
or it does mean that a single http post with more than one parameter ?

anyway is their is a difference in the request time if using normal or multipart post ?
 

Devv

Active Member
Licensed User
Thanks bro , i'am seeing your script now
so making a little change to my script is not possible to send a string (file name) with it ?
i have to change the whole sender and receiver code right ?
 

DonManfred

Expert
Licensed User
so making a little change to my script is not possible to send a string (file name) with it ?
No using postfile

i have to change the whole sender and receiver code right ?
yes.

You can store the filename in this code when sending...
B4X:
    Dim fd As FileData
    fd.Initialize
    fd.Dir = File.DirAssets
    fd.FileName = "snap1.png"
    fd.KeyName = "Aufnahme"
    fd.ContentType = "application/octet-stream"
    files.Add(fd)
 
Top