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:
我已成功将文件从Android上传到我的服务器。我按照本教程进行操作没问题。现在我还需要发送一个字符串以及上传后将添加到文件名的文件。例如:
Upload my file - myFile.mp3
上传我的文件 - myFile.mp3
Upload my string = "|myString"
上传我的string =“| myString”
The file needs to be stored on my server as "myFile.mp3|myString".
该文件需要作为“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.
任何帮助将不胜感激。我只是不太确定在哪里放置字符串来上传它以及如何在PHP代码中检索它。
4 个解决方案
#1
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)
我不相信这是可能的;你只能在标题,文件或基本文本中使用一种内容类型(或者其他一些东西,但是你要谈的是两种)。但是,您可以制作两个单独的帖子,或者制作一个包含文件字节和字符串的帖子(参数文章,应用程序www-x-form-urlencoded)
#2
0
Try uploading using multipart/form-data POST request, you can include other data in headers.
尝试使用multipart / form-data POST请求上传,您可以在标头中包含其他数据。
Check this post : Android send a image and save url
查看此帖子:Android发送图片并保存网址
#3
0
If it is absolutely unavoidable, you can put string in Request header
如果绝对不可避免,可以将字符串放入Request标头中
#4
0
After looking around some more and trying different things, it finally works. I added this to my java code:
在环顾四周并尝试不同的东西之后,它终于有效了。我把它添加到我的java代码中:
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:
这是我的PHP代码获取字符串:
$myString="";
if(isset($_POST['mystring'])) {
$attachToFile = $_POST['myString'];
}
#1
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)
我不相信这是可能的;你只能在标题,文件或基本文本中使用一种内容类型(或者其他一些东西,但是你要谈的是两种)。但是,您可以制作两个单独的帖子,或者制作一个包含文件字节和字符串的帖子(参数文章,应用程序www-x-form-urlencoded)
#2
0
Try uploading using multipart/form-data POST request, you can include other data in headers.
尝试使用multipart / form-data POST请求上传,您可以在标头中包含其他数据。
Check this post : Android send a image and save url
查看此帖子:Android发送图片并保存网址
#3
0
If it is absolutely unavoidable, you can put string in Request header
如果绝对不可避免,可以将字符串放入Request标头中
#4
0
After looking around some more and trying different things, it finally works. I added this to my java code:
在环顾四周并尝试不同的东西之后,它终于有效了。我把它添加到我的java代码中:
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:
这是我的PHP代码获取字符串:
$myString="";
if(isset($_POST['mystring'])) {
$attachToFile = $_POST['myString'];
}