Upload Files to Web Server

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Postby Surbhit » Wed Nov 19, 2008 8:09 pm

venkat wrote:Hi ramonrabello,
Thanks for your reply :), Actually, php code will run on Web server. we just need to pass parameter to that php code. Using below code i can pass data to the php code. :)

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                                 try
  2.                                 {
  3.                                         HttpClient client = new HttpClient();
  4.                                         HttpMethod method = new PostMethod("http://webserver.com/data.php?data=myData");
  5.  
  6.                                         client.executeMethod(method);
  7.                                         a.setText("Ok"+method.getResponseBodyAsString());
  8.                                         method.releaseConnection();
  9.                                 }
  10.                                 catch (Exception e)
  11.                                 {
  12.                                         a.setText("Error");
  13.                                 }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


but, I want to upload File. Can any one tell me, how to do it?? :roll:

Thanks and regads, :)
Venkat.



method.getResponseBodyAsString() line is not working.

Is there any other way to get the response ??

Please help.
Surbhit
Freshman
Freshman
 
Posts: 4
Joined: Mon Nov 17, 2008 4:24 pm

Top

Permission denied

Postby Nimrandir » Sun May 17, 2009 2:58 pm

Hi all!
I followed this tutorial, but i get this error:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. 05-17 15:55:50.353: ERROR/3rd(690): java.net.SocketException: Permission denied (maybe missing INTERNET permission)
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


The java code is the same posted by kat and also the file upload.php. I also created the folder uploads/ with all permission.

I work on Ubuntu 9.04.
Nimrandir
Once Poster
Once Poster
 
Posts: 1
Joined: Sat May 16, 2009 6:15 pm

java.net.SocketException Permission denied (maybe missing IN

Postby role123 » Fri May 29, 2009 4:13 pm

Hi All !!!

When I call a Web Service, it returns me this exception: java.net.SocketException Permission denied (maybe missing INTERNET permission)

Do you the solution ?


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class WS_Connnection {
  2.  
  3.  
  4.  
  5.         static String SERVER_HOST="192.168.0.100";
  6.  
  7.         static int SERVER_PORT = 8000;
  8.  
  9.         static String uri="/sap/bc/srt/wsdl/sdef_ZGET_BP_FROM_LASTNAME/wsdl11/ws_policy/document?sap-client=100";
  10.  
  11.        
  12.  
  13.         public String callService(){
  14.  
  15.                 HttpHost target = new HttpHost(SERVER_HOST, SERVER_PORT, "http");
  16.  
  17.                 return getKeywords(target);
  18.  
  19.                
  20.  
  21.         }
  22.  
  23.         private String getKeywords(HttpHost target) {
  24.  
  25.        String keywords=null;
  26.  
  27.        HttpEntity entity = null;
  28.  
  29.        HttpClient client = new DefaultHttpClient();
  30.  
  31.        HttpGet get = new HttpGet(uri);
  32.  
  33.            try {
  34.  
  35.                   HttpResponse response=client.execute(target, get);
  36.  
  37.                   entity = response.getEntity();
  38.  
  39.                   keywords = EntityUtils.toString(entity);
  40.  
  41.            } catch (Exception e) {
  42.  
  43.                    e.printStackTrace();
  44.  
  45.            } finally {
  46.  
  47.                    if (entity!=null)
  48.  
  49.                    try {
  50.  
  51.                     entity.consumeContent();
  52.  
  53.                    } catch (IOException e) {}
  54.  
  55.            }
  56.  
  57.                         return keywords;
  58.  
  59.           }
  60.  
  61. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


Thanksss ;)
role123
Once Poster
Once Poster
 
Posts: 1
Joined: Fri May 29, 2009 3:38 pm

Postby tweek3867 » Wed Jun 03, 2009 4:46 pm

On the Android phone you have to request permission to use the internet. Try adding the following to your Manifest file?

Code: Select all
<uses-permission android:name="android.permission.INTERNET" />
tweek3867
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Jun 03, 2009 4:44 pm

Postby jhoffman » Wed Jun 17, 2009 2:07 am

raquibulbari wrote:This code worked for me, php code is same as posted before :D


I'm a bit thrown off by this, I've read through all of this thread, and looked at tutorials on the aspects that I struggled with. There were a lot of PHP samples given over the course of this thread. Could someone please summarize exactly which sample worked? Many people have posted snippets of the client side code which worked for them, but left out what PHP server side code worked. It would help me out a lot to see somebody post a pair of snippets which worked together to give them a result!

Thanks in advance for any help! :)
jhoffman
Freshman
Freshman
 
Posts: 9
Joined: Wed Jun 17, 2009 1:58 am

Postby jhoffman » Wed Jun 17, 2009 8:19 pm

I actually solved my own problem after about a week of agonizing over it, but for any future readers of this thread, here are the two pieces of the puzzle, put together, with me saying that it worked for me:

Java code (as previously posted in this thread -- this is not my work):
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import java.io.DataInputStream;
  2. import java.io.DataOutputStream;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.IOException;
  6. import java.net.HttpURLConnection;
  7. import java.net.MalformedURLException;
  8. import java.net.URL;
  9.  
  10. import android.app.Activity;
  11. import android.os.Bundle;
  12. import android.util.Log;
  13.  
  14. public class TestUpload extends Activity {
  15.     /** Called when the activity is first created. */
  16.     @Override
  17.     public void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.main);
  20.     }
  21.    
  22.     private void doFileUpload(){
  23.  
  24.           HttpURLConnection conn = null;
  25.           DataOutputStream dos = null;
  26.           DataInputStream inStream = null;
  27.  
  28.          
  29.           String exsistingFileName = "/sdcard/yourfile.jpg";
  30.           // Is this the place are you doing something wrong.
  31.  
  32.           String lineEnd = "rn";
  33.           String twoHyphens = "--";
  34.           String boundary =  "*****";
  35.  
  36.  
  37.           int bytesRead, bytesAvailable, bufferSize;
  38.  
  39.           byte[] buffer;
  40.  
  41.           int maxBufferSize = 1*1024*1024;
  42.  
  43.           String responseFromServer = "";
  44.  
  45.           String urlString = "http://localhost/uploader.php";
  46.  
  47.  
  48.           try
  49.           {
  50.            //------------------ CLIENT REQUEST
  51.          
  52.           Log.e("MediaPlayer","Inside second Method");
  53.  
  54.           FileInputStream fileInputStream = new FileInputStream(new File(exsistingFileName) );
  55.  
  56.            // open a URL connection to the Servlet
  57.  
  58.            URL url = new URL(urlString);
  59.  
  60.  
  61.            // Open a HTTP connection to the URL
  62.  
  63.            conn = (HttpURLConnection) url.openConnection();
  64.  
  65.            // Allow Inputs
  66.            conn.setDoInput(true);
  67.  
  68.            // Allow Outputs
  69.            conn.setDoOutput(true);
  70.  
  71.            // Don't use a cached copy.
  72.            conn.setUseCaches(false);
  73.  
  74.            // Use a post method.
  75.            conn.setRequestMethod("POST");
  76.  
  77.            conn.setRequestProperty("Connection", "Keep-Alive");
  78.          
  79.            conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
  80.  
  81.            dos = new DataOutputStream( conn.getOutputStream() );
  82.  
  83.            dos.writeBytes(twoHyphens + boundary + lineEnd);
  84.            dos.writeBytes("Content-Disposition: form-data; name="uploadedfile";filename="" + exsistingFileName +""" + lineEnd);
  85.            dos.writeBytes(lineEnd);
  86.  
  87.            Log.e("MediaPlayer","Headers are written");
  88.  
  89.            // create a buffer of maximum size
  90.  
  91.            bytesAvailable = fileInputStream.available();
  92.            bufferSize = Math.min(bytesAvailable, maxBufferSize);
  93.            buffer = new byte[bufferSize];
  94.  
  95.            // read file and write it into form...
  96.  
  97.            bytesRead = fileInputStream.read(buffer, 0, bufferSize);
  98.  
  99.            while (bytesRead > 0)
  100.            {
  101.             dos.write(buffer, 0, bufferSize);
  102.             bytesAvailable = fileInputStream.available();
  103.             bufferSize = Math.min(bytesAvailable, maxBufferSize);
  104.             bytesRead = fileInputStream.read(buffer, 0, bufferSize);
  105.            }
  106.  
  107.            // send multipart form data necesssary after file data...
  108.  
  109.            dos.writeBytes(lineEnd);
  110.            dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
  111.  
  112.            // close streams
  113.            Log.e("MediaPlayer","File is written");
  114.            fileInputStream.close();
  115.            dos.flush();
  116.            dos.close();
  117.  
  118.  
  119.           }
  120.           catch (MalformedURLException ex)
  121.           {
  122.                Log.e("MediaPlayer", "error: " + ex.getMessage(), ex);
  123.           }
  124.  
  125.           catch (IOException ioe)
  126.           {
  127.                Log.e("MediaPlayer", "error: " + ioe.getMessage(), ioe);
  128.           }
  129.  
  130.  
  131.           //------------------ read the SERVER RESPONSE
  132.  
  133.  
  134.           try {
  135.                 inStream = new DataInputStream ( conn.getInputStream() );
  136.                 String str;
  137.                
  138.                 while (( str = inStream.readLine()) != null)
  139.                 {
  140.                      Log.e("MediaPlayer","Server Response"+str);
  141.                 }
  142.                 inStream.close();
  143.  
  144.           }
  145.           catch (IOException ioex){
  146.                Log.e("MediaPlayer", "error: " + ioex.getMessage(), ioex);
  147.           }
  148.  
  149.         }
  150. }
  151.  
Parsed in 0.053 seconds, using GeSHi 1.0.8.4

The PHP server-side (again, posted earlier in this thread, and not my work, but these two never appear in one single post saying that they work together):
Code: Select all
<?php
// Where the file is going to be placed
$target_path = "uploads/";

/* Add the original filename to our target path. 
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
?>


The two things you need to set up in the Java file are: urlString and existingFileName. Configure these such that they match whatever you name your PHP file, and whatever file you're trying to upload. Keep in mind that (as previously posted) you must manually push said file to your emulator's pseudo-SD Card for this to work. (Or have it on a real physical SD card if testing on a real phone). I hope this clears up any confusion that other readers like myself may have in the future!
jhoffman
Freshman
Freshman
 
Posts: 9
Joined: Wed Jun 17, 2009 1:58 am

Top

Postby llPorZall » Fri Jun 19, 2009 5:09 pm

Help Me!! I Create Project ,Take a picture upload picture to Server cannot Work
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class ImageCaptureCallback implements PictureCallback {
  2.         protected final static String TAG = "PUPA";
  3.         private OutputStream filoutputStream;
  4.         private HttpURLConnection connection;
  5.         private DataOutputStream dataOutputStream;
  6.         private DataInputStream inputStream;
  7.         int bytesRead, bytesAvailable, bufferSize;
  8.         int maxBufferSize = 2 * 1024 * 1024;
  9.         String lineEnd = "rn";
  10.         String twoHyphens = "--";
  11.         String boundary = "*****";
  12.         byte[] buffer;
  13.  
  14.         public ImageCaptureCallback(OutputStream filoutputStream) {
  15.                 this.filoutputStream = filoutputStream;
  16.         }
  17.  
  18.         @Override
  19.         public void onPictureTaken(byte[] data, Camera camera) {
  20.                 try {
  21.                         Log.v(TAG, "onPictureTaken=" + data + " length = " + data.length);
  22.                         filoutputStream.write(data);
  23.                         ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(data);
  24.                         // Log.v(TAG,"Read Data:"+fileInputStream.read());
  25.                         URL url = new URL("http://172.30.142.173/upload/");
  26.                         connection = (HttpURLConnection) url.openConnection();
  27.                         connection.setDoInput(true);
  28.                         connection.setDoOutput(true);
  29.                         connection.setUseCaches(false);
  30.                         // Use a post method.
  31.                         connection.setRequestMethod("POST");
  32.                         connection.setRequestProperty("Connection", "Keep-Alive");
  33.                         connection.setRequestProperty("Content-Type",
  34.                                         "multipart/form-data;");
  35.                         dataOutputStream = new DataOutputStream(connection
  36.                                         .getOutputStream());
  37.                         dataOutputStream
  38.                                         .writeBytes("Content-Disposition: form-data; name="xml""
  39.                                                         + lineEnd + lineEnd);
  40.                         bytesAvailable = arrayInputStream.available();
  41.                         bufferSize = Math.min(bytesAvailable, maxBufferSize);
  42.                         Log.v(TAG,"Buffer Size:"+bufferSize);
  43.                         buffer = new byte[bufferSize];
  44.                         bytesRead = arrayInputStream.read(buffer, 0, bufferSize);
  45.                         Log.v(TAG, "connect to server:" + connection.getResponseMessage());
  46.                         while (bytesRead > 0) {
  47.                                 dataOutputStream.write(buffer, 0, bufferSize);
  48.                                 bytesAvailable = arrayInputStream.available();
  49.                                 bufferSize = Math.min(bytesAvailable, maxBufferSize);
  50.                                 bytesRead = arrayInputStream.read(buffer, 0, bufferSize);
  51.                         }
  52.                         dataOutputStream.writeBytes(lineEnd);
  53.                         dataOutputStream.writeBytes(twoHyphens + boundary + twoHyphens
  54.                                         + lineEnd);
  55.                         Log.e(TAG, "File is written");
  56.                         /*
  57.                          * fileInputStream.close(); dataOutputStream.flush();
  58.                          * dataOutputStream.close(); filoutputStream.flush();
  59.                          * filoutputStream.close();
  60.                          */
  61.                 } catch (MalformedURLException ex) {
  62.                         Log.v(TAG, "Ex:" + ex);
  63.                 } catch (IOException e) {
  64.                         Log.v(TAG, "Ex:" + e);
  65.                 }
  66.  
  67.                 try {
  68.                         inputStream = new DataInputStream(connection.getInputStream());
  69.                         String str;
  70.                         while ((str = inputStream.readLine()) != null) {
  71.                                 Log.v(TAG, "Server Response:" + str);
  72.                         }
  73.                         inputStream.close();
  74.                 } catch (IOException e) {
  75.                         Log.v(TAG, "Ex:" + e);
  76.                 }
  77.  
  78.         }
  79.  
  80. }
  81.  
Parsed in 0.047 seconds, using GeSHi 1.0.8.4

PHP Page
Code: Select all
<?php
// Where the file is going to be placed
$target_path = "/upload/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try againg!";
}
?>

Output
There was an error uploading the file, please try againg!

Thanks very much
llPorZall
Freshman
Freshman
 
Posts: 5
Joined: Tue Sep 09, 2008 7:52 am

Postby jhoffman » Fri Jun 19, 2009 7:10 pm

This is a total shot in the dark, but is it possible that this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. $target_path = "/upload/";
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

actually needs to be... this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. $target_path = "upload/";
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
?

In my code, I don't have a slash preceding the upload directory. I'm wondering if perhaps your operating system thinks you're trying to access a directory like var/html/www//upload
instead of var/html/www/upload

I actually had a similar problem with my code, except it was as a result of me forgetting the put the slash AFTER upload, maybe this is your problem?
jhoffman
Freshman
Freshman
 
Posts: 9
Joined: Wed Jun 17, 2009 1:58 am

Postby llPorZall » Sat Jun 20, 2009 8:31 am

jhoffman wrote:This is a total shot in the dark, but is it possible that this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. $target_path = "/upload/";
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

actually needs to be... this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. $target_path = "upload/";
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
?

In my code, I don't have a slash preceding the upload directory. I'm wondering if perhaps your operating system thinks you're trying to access a directory like var/html/www//upload
instead of var/html/www/upload

I actually had a similar problem with my code, except it was as a result of me forgetting the put the slash AFTER upload, maybe this is your problem?

Thanks very much
I change PATH to:
Code: Select all
$target_path = "upload/";

output:There was an error uploading the file, please try againg!

i create html form for testing php upload page but it's doesn't work!

So I want to know there have any wrong code in the Java part
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class ImageCaptureCallback implements PictureCallback {
  2.         protected final static String TAG = "PUPA";
  3.         private OutputStream filoutputStream;
  4.         private HttpURLConnection connection;
  5.         private DataOutputStream dataOutputStream;
  6.         private DataInputStream inputStream;
  7.         int bytesRead, bytesAvailable, bufferSize;
  8.         int maxBufferSize = 2 * 1024 * 1024;
  9.         String lineEnd = "rn";
  10.         String twoHyphens = "--";
  11.         String boundary = "*****";
  12.         byte[] buffer;
  13.         private String string = "/sdcard/DCIM/100media/IMAG0001.jpg";
  14.  
  15.         public ImageCaptureCallback(OutputStream filoutputStream) {
  16.                 this.filoutputStream = filoutputStream;
  17.         }
  18.  
  19.         @Override
  20.         public void onPictureTaken(byte[] data, Camera camera) {
  21.                 try {
  22.                         Log.v(TAG, "onPictureTaken=" + data + " length = " + data.length);
  23.                         filoutputStream.write(data);
  24.                         FileInputStream arrayInputStream = new FileInputStream(new File(string));
  25.                         // Log.v(TAG,"Read Data:"+fileInputStream.read());
  26.                         URL url = new URL("http://172.30.142.173/upload/uploader.php");
  27.                         connection = (HttpURLConnection) url.openConnection();
  28.                         connection.setDoInput(true);
  29.                         connection.setDoOutput(true);
  30.                         connection.setUseCaches(false);
  31.                         // Use a post method.
  32.                         connection.setRequestMethod("POST");
  33.                         connection.setRequestProperty("Connection", "Keep-Alive");
  34.                         connection.setRequestProperty("Content-Type",
  35.                                         "multipart/form-data;boundary=" + boundary);
  36.                        
  37.                         dataOutputStream = new DataOutputStream(connection
  38.                                         .getOutputStream());
  39.                         dataOutputStream
  40.                                         .writeBytes("Content-Disposition: form-data; name="uploadedfile";filename=""
  41.                                                         + "IMAG0001.jpg" + """ + lineEnd);
  42.                         dataOutputStream.writeBytes(lineEnd);
  43.                        
  44.                         bytesAvailable = arrayInputStream.available();
  45.                         bufferSize = Math.min(bytesAvailable, maxBufferSize);
  46.                         Log.v(TAG, "Buffer Size:" + bufferSize);
  47.                         buffer = new byte[bufferSize];
  48.                         bytesRead = arrayInputStream.read(buffer, 0, bufferSize);
  49.                         Log.v(TAG, "connect to server:" + connection.getResponseMessage());
  50.                        
  51.                         while (bytesRead > 0) {
  52.                                 Log.v(TAG, "Read:" + bytesRead);
  53.                                 dataOutputStream.write(buffer, 0, bufferSize);
  54.                                 bytesAvailable = arrayInputStream.available();
  55.                                 bufferSize = Math.min(bytesAvailable, maxBufferSize);
  56.                                 bytesRead = arrayInputStream.read(buffer, 0, bufferSize);
  57.                         }
  58.                        
  59.                         dataOutputStream.writeBytes(lineEnd);
  60.                         dataOutputStream.writeBytes(twoHyphens + boundary + twoHyphens
  61.                                         + lineEnd);
  62.                        
  63.                         Log.e(TAG, "File is written");
  64.                         arrayInputStream.close();
  65.                         dataOutputStream.flush();
  66.  
  67.                 } catch (MalformedURLException ex) {
  68.                         Log.v(TAG, "Ex:" + ex);
  69.                 } catch (IOException e) {
  70.                         Log.v(TAG, "Ex:" + e);
  71.                 }
  72.  
  73.                 try {
  74.                         inputStream = new DataInputStream(connection.getInputStream());
  75.                         String str;
  76.                         while ((str = inputStream.readLine()) != null) {
  77.                                 Log.v(TAG, "Server Response:" + str);
  78.                         }
  79.                         dataOutputStream.close();
  80.                 } catch (IOException e) {
  81.                         Log.v(TAG, "Ex:" + e);
  82.                 }
  83.  
  84.         }
  85.  
  86. }
  87.  
Parsed in 0.049 seconds, using GeSHi 1.0.8.4
llPorZall
Freshman
Freshman
 
Posts: 5
Joined: Tue Sep 09, 2008 7:52 am

Postby jhoffman » Sat Jun 20, 2009 7:56 pm

Do you mean that when you test your PHP with your HTML form, it does work or does not work?

If your html form is also failing, I would say the problem is with your PHP. Just from glancing over your code I didn't see anything obviously wrong with it, but I am VERY new to this type of code, and not really going to be super useful at finding intricacies that are wrong.

What I would recommend is that you narrow down exactly where in your code things start to go wrong. If you use eclipse, set up some breakpoints so you can peek at your variables in debug mode. If not, use the log.e method call to output contents of your variables in a bunch of places along the code's execution. Look at these using the Log tool (part of DDMS or can be run stand-alone I believe).

When I had trouble with my http code, I was able to narrow things down in this way and determined that my specific problem was actually related to the file access on my Android and NOT any of the web stuff. No real guarantee that you'll be that lucky, but narrowing down the problem always helps!
jhoffman
Freshman
Freshman
 
Posts: 9
Joined: Wed Jun 17, 2009 1:58 am

Postby llPorZall » Sat Jun 20, 2009 8:30 pm

jhoffman wrote:Do you mean that when you test your PHP with your HTML form, it does work or does not work?

If your html form is also failing, I would say the problem is with your PHP. Just from glancing over your code I didn't see anything obviously wrong with it, but I am VERY new to this type of code, and not really going to be super useful at finding intricacies that are wrong.

What I would recommend is that you narrow down exactly where in your code things start to go wrong. If you use eclipse, set up some breakpoints so you can peek at your variables in debug mode. If not, use the log.e method call to output contents of your variables in a bunch of places along the code's execution. Look at these using the Log tool (part of DDMS or can be run stand-alone I believe).

When I had trouble with my http code, I was able to narrow things down in this way and determined that my specific problem was actually related to the file access on my Android and NOT any of the web stuff. No real guarantee that you'll be that lucky, but narrowing down the problem always helps!


Thanks very much MR.jhoffman
I'm Sending file to server is success
llPorZall
Freshman
Freshman
 
Posts: 5
Joined: Tue Sep 09, 2008 7:52 am

Postby jhoffman » Sun Jun 21, 2009 2:44 am

Congrats! I'm glad to hear it!

Are you able to send from an actual GPhone, or just the emulator? I'm having some errors sending from my Ion phone, but the emulator works flawlessly. I get file not found errors as described in the thread I made

Let me know if you are able to send from your phone as well as the emulator, I'd be interested to learn if I've done something strange to stop my program from working on the real phone!
jhoffman
Freshman
Freshman
 
Posts: 9
Joined: Wed Jun 17, 2009 1:58 am

an equivalent in java servlet for the php uploader

Postby draviaz » Sun Aug 16, 2009 2:31 pm

Hi, I would like to use java servlets instead of php for managing the server-side upload. Can somebody help?
draviaz
Freshman
Freshman
 
Posts: 2
Joined: Mon Aug 10, 2009 12:43 pm

This worked for me too...here is html test harness

Postby jbrohan » Fri Aug 28, 2009 11:20 am

First of all I would like to thank those who added to this most valuable resource. My project is moving ahead now. This is a minimalist html script which will test TestUpload.php in the same web folder. You can run this form from a browser!

Good luck and Blessings to all
Thanks again.
John

<form enctype='multipart/form-data' action='TestUpload.php' method='POST'>
<!-- MAX_FILE_SIZE must precede the file input field -->
Phone: <input type = 'text' name = 'phone' value = ''/>
<input type='hidden' name='MAX_FILE_SIZE' value='10000000' />
<!-- Name of input element determines name in $_FILES array -->
<br/>Search for the picture.<input name='uploadedfile' type='file' size= '50' />
<br/>
<br/>
<input type='submit' value='Send in picture'/>
</form>
jbrohan
Junior Developer
Junior Developer
 
Posts: 14
Joined: Fri Aug 28, 2009 11:12 am
Location: Montreal

java.io.FileNotFoundException

Postby sng2392 » Tue Oct 20, 2009 12:36 am

Does anyone have an idea to why I get this error?

10-19 23:02:06.141: ERROR/MediaPlayer(899): error: http://www.webhostsomewhere.com/SomeFolder/upload.aspx
10-19 23:02:06.141: ERROR/MediaPlayer(899): java.io.FileNotFoundException: http://www.webhostsomewhere.com/SomeFolder/upload.aspx
10-19 23:02:06.141: ERROR/MediaPlayer(899): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1064)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at com.vtind.guesswho.ImageDownload.uploadFile(ImageDownload.java:217)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at com.vtind.guesswho.SendView$2.onClick(SendView.java:85)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at android.view.View.performClick(View.java:2179)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at android.view.View.onTouchEvent(View.java:3828)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at android.widget.TextView.onTouchEvent(TextView.java:6291)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at android.view.View.dispatchTouchEvent(View.java:3368)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1707)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1197)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at android.app.Activity.dispatchTouchEvent(Activity.java:1993)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1691)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at android.view.ViewRoot.handleMessage(ViewRoot.java:1525)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at android.os.Handler.dispatchMessage(Handler.java:99)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at android.os.Looper.loop(Looper.java:123)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at android.app.ActivityThread.main(ActivityThread.java:3948)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at java.lang.reflect.Method.invokeNative(Native Method)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at java.lang.reflect.Method.invoke(Method.java:521)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
10-19 23:02:06.141: ERROR/MediaPlayer(899): at dalvik.system.NativeStart.main(Native Method)



My client side code is identical to what has been posted by jhoffman
sng2392
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Oct 20, 2009 12:31 am

Top
PreviousNext

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests