2010-04-15 97 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