2014-03-01 82 views
0

我有一個Backbone.js UI與Jersey中實現的RESTful服務接口。從服務器目錄中返回圖像的RESTful服務

我可以知道如何實現一個RESTful服務來從服務器目錄加載圖像並將它們顯示在UI上嗎?

+1

你能告訴我們你到目前爲止有什麼嗎?如果我們知道你已經做了什麼,它會更容易幫助。 – bejonbee

回答

0

您可以在Response中返回一個File對象。

@GET 
@Path("/{filename}") 
@Produces(MediaType.APPLICATION_OCTET_STREAM) 
public Response getFile(@PathParam("filename") final String fileName) { 

    if (fileName == null || fileName.isEmpty()) 
     return Response.status(Response.Status.BAD_REQUEST).build(); 
    File file = new File(fileDirectoryPath, fileName); 
    return Response.ok(file).build(); 
} 

fileDirectoryPath是要從中提取文件的目錄的路徑的字符串。