Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Basically you need two sides. The first one is on Android. You have to send (Do it in an ASyncTask e.x.) the data to your webservice. Here I made a little method for you, which sends a file and some additional POST values to an URL:</p> <pre><code>private boolean handleFile(String filePath, String mimeType) { HttpURLConnection connection = null; DataOutputStream outStream = null; DataInputStream inStream = null; String lineEnd = "\r\n"; String twoHyphens = "--"; String boundary = "*****"; int bytesRead, bytesAvailable, bufferSize; byte[] buffer; int maxBufferSize = 1*1024*1024; String urlString = "http://your.domain.com/webservice.php"; try { FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(new File(filePath)); } catch(FileNotFoundException e) { } URL url = new URL(urlString); connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.setDoOutput(true); connection.setUseCaches(false); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); connection.setRequestMethod("POST"); connection.setRequestProperty("Connection", "Keep-Alive"); connection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary); outStream = new DataOutputStream(connection.getOutputStream()); // Some POST values outStream.writeBytes(addParam("additional_param", "some value"); outStream.writeBytes(addParam("additional_param 2", "some other value"); // The file with the name "uploadedfile" outStream.writeBytes(twoHyphens + boundary + lineEnd); outStream.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + filePath +"\"" + lineEnd + "Content-Type: " + mimeType + lineEnd + "Content-Transfer-Encoding: binary" + lineEnd); outStream.writeBytes(lineEnd); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); buffer = new byte[bufferSize]; bytesRead = fileInputStream.read(buffer, 0, bufferSize); while (bytesRead &gt; 0) { outStream.write(buffer, 0, bufferSize); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); bytesRead = fileInputStream.read(buffer, 0, bufferSize); } outStream.writeBytes(lineEnd); outStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); fileInputStream.close(); outStream.flush(); outStream.close(); } catch (MalformedURLException e) { Log.e("APP", "MalformedURLException while sending\n" + e.getMessage()); } catch (IOException e) { Log.e("APP", "IOException while sending\n" + e.getMessage()); } // This part checks the response of the server. If its "UPLOAD OK" the method returns true try { inStream = new DataInputStream( connection.getInputStream() ); String str; while (( str = inStream.readLine()) != null) { if(str=="UPLOAD OK") { return true; } else { return false; } } inStream.close(); } catch (IOException e){ Log.e("APP", "IOException while sending\n" + e.getMessage()); } return false; } </code></pre> <p>Now, we have got the other side: <a href="http://your.domain.com/webservice.php" rel="nofollow noreferrer">http://your.domain.com/webservice.php</a> Your server. It needs some logic, for example in PHP, to handle the sent POST request. Something like this would work:</p> <pre><code>&lt;?php $target_path = "videos/"; $target_path = $target_path.'somename.3gp'; if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { exit("UPLOAD OK"); } else { exit("UPLOAD NOT OK"); } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload