上传图片时,文本字段的编码是什么编码?

30 views
Skip to first unread message

leen

unread,
Jan 19, 2011, 11:23:45 PM1/19/11
to fanfo...@googlegroups.com
上传图片时,文本字段的编码是什么编码?
//params.put("status", _msg);
//params.put("status", URLEncoder.encode(_msg, "UTF-8"));
//params.put("status", new String(_msg.getBytes("iso8859-1"), "UTF-8"));
 params.put("status", new String(_msg.getBytes(), "GBK"));
怎么这几种都不行啊。

mcxiaoke

unread,
Jan 20, 2011, 12:22:20 AM1/20/11
to fanfo...@googlegroups.com
错误信息呢?贴上来看看,不一定是编码的问题

leen

unread,
Jan 20, 2011, 2:03:03 AM1/20/11
to fanfo...@googlegroups.com
没错误,只是上传后是乱码。

http://fanfou.com/marktown

Juguang XIAO

unread,
Jan 20, 2011, 3:37:07 AM1/20/11
to fanfo...@googlegroups.com
你用的Java方法支持RFC1867么?

下面是我的一段Objective-C/iPhone代码,是能用的。你可以参考一下


// http://www.ietf.org/rfc/rfc1867.txt
NSString *boundary = @"0xKhTmLbOuNdArY";
NSString *contentType = [NSString
stringWithFormat:@"multipart/form-data; boundary=%@", boundary, nil];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];


NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",
boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition:
form-data; name=\"status\";\r\n\r\n%@\r\n", name]
dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",
boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Disposition:
form-data; name=\"photo\"; filename=\"iphonefile.jpg\"\r\n"]
dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type:
application/octet-stream\r\n\r\n"]
dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imgData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",
boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];

2011/1/20 leen <leen...@gmail.com>:
> 没错误,只是上传后是乱码。
>
> http://fanfou.com/marktown

--
=============
Juguang XIAO
Beijing and Singapore

Juguang XIAO

unread,
Jan 20, 2011, 3:40:45 AM1/20/11
to fanfo...@googlegroups.com
http://fanfou.com/workisreligion

刚刚测试了一个。正常。

2011/1/20 Juguang XIAO <jug...@gmail.com>:

.rex

unread,
Jan 20, 2011, 3:50:09 AM1/20/11
to fanfo...@googlegroups.com
我在命令行下是这样测试的: mac os /utf8

curl -u name:password -F "photo=@x.png;type=image/png" -F status="健康" "http://api.fanfou.com/photos/upload.xml"

效果如:

fan zeyi

unread,
Jan 20, 2011, 5:08:15 AM1/20/11
to fanfo...@googlegroups.com


2011/1/20 .rex <r...@zhasm.com>

对了 问一个问题  我最近上传图片一直是502 错误
不管是直接调用API还是 用手机版上传 一直是502
不知道是什么情况

--
For a better code.
    Zeray Fan
I ❤ Kylin and Kylin ❤ Me
Twitter: @fanzeyi
http://www.fanhe.org/
Reply all
Reply to author
Forward
0 new messages