我正在尝试将数据导入到parse.com,这样我就可以测试我的应用程序了(我是新解析的,之前我从未使用过json)。
你能给我一个我可以用来导入二进制文件(图像)的json文件的例子吗?
注意:我正在尝试从数据浏览器以批量方式上传我的数据。这是一个screencap:i.stack.imgur.com/bw9b4.png
答案 0 :(得分:0)
在解析文档中我认为2个部分可以帮助你取决于你是否想要使用android sdk的REST api。
rest api - 请参阅有关POST的部分,上传可以使用REST POST解析的文件。
SDk - 请参阅“文件”部分
Rest的代码包括以下内容:
使用一些具有“ByteArrayEntity”类或其他东西的HttpClient实现
将您的图像映射到bytearrayEntity并使用httpclient中的Mime / Type的正确标头对其进行POST ...
case POST:
HttpPost httpPost = new HttpPost(url); //urlends "audio OR "pic"
httpPost.setProtocolVersion(new ProtocolVersion("HTTP", 1,1));
httpPost.setConfig(this.config);
if ( mfile.canRead() ){
FileInputStream fis = new FileInputStream(mfile);
FileChannel fc = fis.getChannel(); // Get the file's size and then map it into memory
int sz = (int)fc.size();
MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
data2 = new byte[bb.remaining()];
bb.get(data2);
ByteArrayEntity reqEntity = new ByteArrayEntity(data2);
httpPost.setEntity(reqEntity);
fis.close();
}
,,,
request.addHeader("Content-Type", "image/*") ;
pseudocode for post the runnable to execute the http request
答案 1 :(得分:0)
允许加载到parse.com的唯一二进制数据是图像。在其他情况下,如文件或流等,最合适的解决方案是在另一个专用存储中存储二进制数据的链接,以获取此类信息。