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.

1

4 Answers 4

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)

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

0

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

Comments

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']; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.