| Author |
Message |
venkat Senior Developer
Joined: 27 Nov 2007 Posts: 152 Location: India
|
|
| Back to top |
|
 |
ramonrabello Freshman
Joined: 05 Jan 2008 Posts: 4
|
Posted: Sat Jan 05, 2008 8:59 pm Post subject: Re: Upload Files to Web Server |
|
|
| venkat wrote: | Hi to All,
is it possible to upload files from android to web server, In web server i am using Php file to upload files.
This is sample php file to upload files to web server.
| Code: | <?php
$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!";
}
?> |
Using above Php code , i can upload files from j2me. Can you any one tell me how to upload files from android.
Thanks and Regards,
Venkat. |
Well, if u need to upload I think that u need to upload the .apk (deploy file of Android) instead a .jar or a .jad file like in j2me. But u have to update your web server configuration to accept the MIME type .apk to allow the upload. |
|
| Back to top |
|
 |
venkat Senior Developer
Joined: 27 Nov 2007 Posts: 152 Location: India
|
|
| Back to top |
|
 |
Lex Developer
Joined: 16 Nov 2007 Posts: 30
|
|
| Back to top |
|
 |
venkat Senior Developer
Joined: 27 Nov 2007 Posts: 152 Location: India
|
Posted: Sun Jan 06, 2008 2:52 pm Post subject: |
|
|
Thanks for your reply Lex. I will check it out
Regards,
Venkat  |
|
| Back to top |
|
 |
venkat Senior Developer
Joined: 27 Nov 2007 Posts: 152 Location: India
|
|
| Back to top |
|
 |
rmeph Senior Developer
Joined: 10 Dec 2007 Posts: 109 Location: India
|
Posted: Mon Jan 07, 2008 3:15 pm Post subject: |
|
|
hi Lex,
do u know how simple file in android upload to web server????  |
|
| Back to top |
|
 |
cabernet1976 Senior Developer
Joined: 16 Nov 2007 Posts: 146 Location: China
|
|
| Back to top |
|
 |
venkat Senior Developer
Joined: 27 Nov 2007 Posts: 152 Location: India
|
Posted: Mon Jan 07, 2008 3:49 pm Post subject: |
|
|
Hi cabernet,
Thanks for your reply, Is it correct link you have provided? I can't find any article related to upload files to web server.
Thanks and Regards,
Venkat. _________________ Regards,
Venkat. |
|
| Back to top |
|
 |
rmeph Senior Developer
Joined: 10 Dec 2007 Posts: 109 Location: India
|
Posted: Mon Jan 07, 2008 4:13 pm Post subject: |
|
|
i can't find any article in that link(https://jickr.dev.java.net).
plz forward correct link.......  |
|
| Back to top |
|
 |
cabernet1976 Senior Developer
Joined: 16 Nov 2007 Posts: 146 Location: China
|
|
| Back to top |
|
 |
venkat Senior Developer
Joined: 27 Nov 2007 Posts: 152 Location: India
|
Posted: Tue Jan 08, 2008 6:05 am Post subject: |
|
|
HI Cabernet,
i got zip file. I will go though this and let you know , If I have any query.
Thanks and Regards,
Venkat. _________________ Regards,
Venkat. |
|
| Back to top |
|
 |
rmeph Senior Developer
Joined: 10 Dec 2007 Posts: 109 Location: India
|
Posted: Tue Jan 08, 2008 11:38 am Post subject: |
|
|
| also tell if i have any txt file.......... |
|
| Back to top |
|
 |
Katharnavas Senior Developer
Joined: 04 Dec 2007 Posts: 100 Location: India
|
Posted: Wed Jan 09, 2008 5:35 am Post subject: |
|
|
| venkat wrote: | HI Cabernet,
i got zip file. I will go though this and let you know , If I have any query.
Thanks and Regards,
Venkat. |
try this hope it will do
| Java: | String exsistingFileName = "/sdcard/t1.mp3";
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
try
{
//------------------ CLIENT REQUEST
Log.e(Tag,"Inside second Method");
FileInputStream fileInputStream = new FileInputStream(new File(exsistingFileName) );
// open a URL connection to the Servlet
URL url = new URL(urlString);
// Open a HTTP connection to the URL
conn = (HttpURLConnection) url.openConnection();
// Allow Inputs
conn.setDoInput(true);
// Allow Outputs
conn.setDoOutput(true);
// Don't use a cached copy.
conn.setUseCaches(false);
// Use a post method.
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
dos = new DataOutputStream( conn.getOutputStream() );
dos.writeBytes(twoHyphens + boundary + lineEnd);
dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + exsistingFileName +"\"" + lineEnd);
dos.writeBytes(lineEnd);
Log.e(Tag,"Headers are written");
// create a buffer of maximum size
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];
// read file and write it into form...
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while (bytesRead > 0)
{
dos.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
// send multipart form data necesssary after file data...
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
// close streams
Log.e(Tag,"File is written");
fileInputStream.close();
dos.flush();
dos.close();
}
catch (MalformedURLException ex)
{
Log.e(Tag, "error: " + ex.getMessage(), ex);
}
catch (IOException ioe)
{
Log.e(Tag, "error: " + ioe.getMessage(), ioe);
} |
Last edited by Katharnavas on Wed Jan 09, 2008 1:18 pm; edited 1 time in total |
|
| Back to top |
|
 |
rmeph Senior Developer
Joined: 10 Dec 2007 Posts: 109 Location: India
|
Posted: Wed Jan 09, 2008 8:29 am Post subject: |
|
|
hi all,
any one tel me a simple file in android how to upload on server............
my file in
| Java: | File f = new File(aDirectory.getAbsolutePath()); |
that upload on server using http protocal............. |
|
| Back to top |
|
 |
|