2010-04-15 44 views
0
  int start=0,flag=1; 
      long size=blobInfo.getSize(),fetched=0,fetch; 
      byte temp[] = null; 

      while(fetched<size){ 
       if(size-fetched>MAX_BLOB_FETCH_SIZE) 
        fetch=MAX_BLOB_FETCH_SIZE; 
       else 
        fetch=size-fetched; 

       temp=blobstoreService.fetchData(blobKey,fetched,fetch); 

       fetched+=fetch; 
       out.println(temp); 
     } 

我试图使用上面的代码打印上传的文本文件的数据,但它似乎并没有工作。无法打印上传的blob数据

+0

。告诉我们你如何获得上传的项目。 – Bozho 2010-04-15 08:32:58

+0

你为什么试图通过你的代码获取并显示blob? blobstore背后的想法是,您可以直接向用户提供服务 - 详细信息请参阅文档。 – 2010-04-15 09:44:09

+0

@Bohzo temp = blobstoreService.fetchData(blobKey,fetched,fetch);代码中的 行将上传项目的一部分作为字节数组提取,称为获取数据。 – 2010-04-15 10:01:50

回答

1

我知道了。 作为

而(blobInfo.getSize()> positionInBlob){ 长endIndex的= Math.min(blobInfo.getSize(),positionInBlob + CHUNKSIZE); chunk = blobstoreService.fetchData(blobKey,positionInBlob,endIndex); positionInBlob + = chunk.length;

  for(int j=0;j<chunk.length;j++){ 
      int c=chunk[j]; 
      out.println((char)c); 
     } 

    } 
0

我的斑点笔记: http://code.google.com/p/gwt-examples/wiki/DemoGAEMultiFileBlobUpload

我的访存:

私人字节[] getImageBytes(BlobData blobData){ 如果(blobData == NULL){ 返回NULL; }

BlobKey blobKey = new BlobKey(blobData.getKey()); 
if (blobKey == null) { 
    return null; 
} 

ByteArrayOutputStream out = new ByteArrayOutputStream(); 
long filesize = blobData.getSize(); 
int chunkSize = 1024; 
long offset = 0; 
while (offset < filesize) { 

    long limit = offset + chunkSize - 1; 
    if (filesize < limit) { 
    limit = filesize; 
    } 

    System.out.println("offset=" + offset + " limit=" + limit); 

    byte[] b = null; 
    try { 
    b = blobstoreService.fetchData(blobKey, offset, limit); 
    } catch (Exception e) { 
    e.printStackTrace(); 
    return null; 
    } 
    try { 
    out.write(b); 
    } catch (IOException e) { 
    e.printStackTrace(); 
    return null; 
    } 

    offset += chunkSize; 
    if (offset > filesize) { 
    offset = filesize; 
    } 
} 

byte[] filebytes = out.toByteArray(); 

System.out.println("getImageBytes(): filebytes size: " + filebytes.length + " blobData.size=" + blobData.getSize()); 

return filebytes; 

}

您所提供的代码是完全不相干
+0

这里的帖子不允许签名[常见问题#签名] – 2012-11-06 00:21:52