2014-07-05 59 views
0

我试图导入数据到parse.com,所以我可以测试我的应用程序(我是新来解析,我从来没有使用JSON之前)。将二进制数据导入到parse.com

你可以给我一个我可以用来导入二进制文件(图像)的json文件的例子吗?

注意:我正尝试从数据浏览器上传批量导向数据。这里是一个screencap:i.stack.imgur.com/bw9b4.png

回答

0

在解析文档,我认为2个部分可以帮助你,取决于你是否想使用android sdk的REST api。

rest api - 请参阅关于POST的章节,上传可上传到使用REST POST解析的文件。

SDK - 见的“文件”休息

代码包括以下内容:

使用具有“ByteArrayEntity”类或某事

一些HttpClient的实现地图的图像bytearrayEntity,并张贴httpclient中Mime/Type的正确标题...

  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 
+0

对不起,我的问题是不够清楚..实际上我试图直接从数据浏览器批量上传数据。我做了一个json文件,它对我的​​字符串,数字等工作正常..但我找不到用于上传'文件'类型的正确的代码。我将添加一个截图。 – RidRoid

0

允许加载到parse.com的唯一二进制数据ar e图像。在其他情况下,如文件或流..等最合适的解决方案是存储链接到二进制数据在另一个专用存储这种类型的信息。