0

I have successfully been able to upload files from Android to my server. I followed this tutorial and it works with no problem. Now I need to also send a string along with the file that will be added to the file name once it is uploaded. For example:

Upload my file - myFile.mp3

Upload my string = "|myString"

The file needs to be stored on my server as "myFile.mp3|myString".

Any help would be greatly appreciated. I'm just not quite sure where to place the string to upload it and how to retrieve it in the PHP code.

Mark
  • 1,130
  • 3
  • 17
  • 32
  • Look at http://stackoverflow.com/questions/7037717/upload-an-image-and-audio-in-one-request-in-android/7038888#7038888 .. – user370305 Aug 24 '12 at 06:08

4 Answers4

0

I don't believe this is possible; you can only have one content-type in the header, file, or basic text (or a bunch of other things, but there are the two you're talking about). You can, however, make two seperate posts, or make one post containing bytes of the file and a string (paramater post, application www-x-form-urlencoded)

Alex Coleman
  • 7,216
  • 1
  • 22
  • 31
0

Try uploading using multipart/form-data POST request, you can include other data in headers.

Check this post : Android send a image and save url

Community
  • 1
  • 1
Eldhose M Babu
  • 14,382
  • 8
  • 39
  • 44
0

If it is absolutely unavoidable, you can put string in Request header

Chris
  • 5,584
  • 9
  • 40
  • 58
0

After looking around some more and trying different things, it finally works. I added this to my java code:

dos.writeBytes(twoHyphens + boundary + lineEnd); 
dos.writeBytes("Content-Disposition: form-data; name=\"mystring\"" + lineEnd + lineEnd);
dos.writeBytes("myString" + lineEnd);

and this to my PHP code to get the string:

$myString="";       

if(isset($_POST['mystring'])) {
    $attachToFile = $_POST['myString']; 
}
Mark
  • 1,130
  • 3
  • 17
  • 32