【发布时间】:2014-05-13 08:45:08
【问题描述】:
我需要像下面这样发送 JSON:
story = {
:story => {
:uuid => "1234567890",
:title => "Title",
:subtitle => "Subtitle",
:private => true,
:bytes => [
{
:uuid => "1234567890",
:timelineDate => "1970-01-01T00:00:00.000+00:00",
:caption => "Byte 1"
:photo => image
}
}
没有图像发送一切正常,但图像作为位图在 JSON 服务器返回错误
我以这种方式发送的请求:
RestClient client = RestClient.getInstance(this, URL);
client.addHeader("Content-Type", "application/json");
client.addHeader("Authorization", "Token token=" token);
//create JSON from Java objects
client.setJSONString(json);
client.execute(RestClient.RequestMethod.POST);
必须是什么类型的图像才能将其发送到 Rails 服务器?
Rails 服务器想要这样的图像:
#<Rack::Test::UploadedFile:0x00000103ea6330
@content_type="image/jpg",
@original_filename="photo.jpg",
@tempfile=
#<File:/var/folders/1j/8b1khcf57fv1stf87gcylk8c0000gn/T/photo.jpg20140512-3303-1u2nkqo>
【问题讨论】:
-
如果你想以 JSON 格式发送图片,你必须将图片转换为 Base64 字符串然后发送才能工作
标签: android ruby-on-rails ruby json bitmap