I'm currently not specifying a MIME type, do I need to do this? Here
is the PHP code I'm using:
<?php
$target_path = "uploads/";
$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!";
}
?>
On Mar 19, 10:11 am, Carl Whalley <[email protected]> wrote:
> Sure its not the MIME type not being defined correctly on the server?
> Try changing the extensions to txt, bin, etc and if you see a pattern
> where some work and others don't then thats the culprit.
>
> --
> Android Academy:http://www.androidacademy.com
>
> On Mar 18, 8:36 pm, Bobbie <[email protected]> wrote:
>
> > I have included my code below. I have the code working for image
> > uploads, but was wondering how to get it to work with audio and video
> > files? Please let me know if you have any suggestions/tutorials.
>
> > // WORKS WITH JPEG FILE -- String existingFileName =
> > "/sdcard/dcim/
> > Camera/1225231027592.jpg";
> > String existingFileName = "/sdcard/Music/kryptonite.mp3";
> > // DOES
> > NOT WORK WITH MP3 FILE
> > File uploadFile = new File(existingFileName);
> > FileInputStream fileInputStream = new
> > FileInputStream(uploadFile);
>
> > String lineEnd = "\r\n";
> > String twoHyphens = "--";
> > String boundary = "*****";
> > try
> > {
> > URL connectURL = new
> > URL("http://www.mysite.com/uploads.php");
>
> > // connectURL is a URL object
> > HttpURLConnection conn = (HttpURLConnection)
> > connectURL.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");
>
> > // set post headers
> > conn.setRequestProperty("Connection","Keep-Alive");
> >
> > conn.setRequestProperty("Content-Type","multipart/form-
> > data;boundary="+boundary);
>
> > // open data output stream
> > DataOutputStream dos = new
> > DataOutputStream(conn.getOutputStream
> > ());
> > dos.writeBytes(twoHyphens + boundary + lineEnd);
> > dos.writeBytes("Content-Disposition: form-data;
> > name=\"uploadedfile
> > \";filename=\""+existingFileName +"\"" + lineEnd);
> > dos.writeBytes(lineEnd);
>
> > // create a buffer of maximum size
> > int bytesAvailable = fileInputStream.available();
> > int maxBufferSize = 1024;
> > int bufferSize = Math.min(bytesAvailable,
> > maxBufferSize);
> > byte[] buffer = new byte[bufferSize];
>
> > // read file and write it into form...
> > int 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
> > fileInputStream.close();
> > dos.flush();
>
> > InputStream is = conn.getInputStream();
> > int ch;
>
> > StringBuffer b =new StringBuffer();
> > while( ( ch = is.read() ) != -1 ) {
> > b.append( (char)ch );
> > }
>
> > String s=b.toString();
> > dos.close();
> > }
> > catch (MalformedURLException ex) {
> > // Log.e(Tag, "error: " + ex.getMessage(), ex);
> > }
> > catch (IOException ioe) {
> > // Log.e(Tag, "error: " + ioe.getMessage(), ioe);
> > }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---