サムネイルを含むリスト ビューを実装する必要があり、このサムネイルは volley networkimageview を使用して読み込まれます。コントローラーが次のようになっている場合、これをどのように実装しますか。
@RequestMapping (value="/rest/getphoto/",produces=MediaType.IMAGE_PNG_VALUE)
public @ResponseBody byte [] get Image (@RequestParam ("imageId"));
ボレーの使用法に関する多くの例を見つけましたが、役に立ちません。その上、私は安全な接続を使用しています。前もって感謝します。
編集:Spring MVC プロジェクトにコントローラー コードと、画像を要求する Android クライアントのコードの一部を含めています。
* 春の MVC *
@RequestMapping(value = "/rest/singlephoto/", method = RequestMethod.GET, produces = MediaType.IMAGE_PNG_VALUE)
public @ResponseBody byte[] base64ImageForAndroid(@RequestParam("photoId") String photoIdParam, HttpServletRequest request)
{
String pathToLoad = "/path/default.png";
//HashMap<String, String> retVal = new HashMap<String, String>();
byte[] retVal;
try
{
long photoId = Long.parseLong(photoIdParam);
Photo photo = photoManager.getSinglePhoto(photoId);
if (photo != null)
pathToLoad = photo.getPath();
}
catch (NumberFormatException ex)
{
}
finally
{
try
{
File file = new File(pathToLoad);
retVal = FileUtils.readFileToByteArray(file);
}
catch (IOException ex)
{
retVal = null;
}
}
return retVal;
*ボレーでリクエストするAndroidクライアント*
Bitmap thumb = imageCache.get(item.getThumbnailUrl() + "thumb");
if (thumb == null)
{
HttpHeaders headers = new HttpHeaders();
HttpBasicAuthentication auth = new HttpBasicAuthentication(this.username, this.password);
headers.setAuthorization(auth);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_OCTET_STREAM));
Listener<byte[]> imageLoadedListener = new Response.Listener<byte[]>() {
@Override
public void onResponse(byte[] photoByteArray) {
Bitmap bitmap = EfficientImageLoading.decodeBitmapFromByteArray(photoByteArray, viewHolder.thumbnail.getWidth(), viewHolder.thumbnail.getHeight());
viewHolder.thumbnail.setImageBitmap(bitmap);
imageCache.put(item.getThumbnailUrl() + "thumb", bitmap);
//Cache full size and recycle
Bitmap fullBmp = EfficientImageLoading.decodeImageFromByteFullSize(photoByteArray);
imageCache.put(item.getThumbnailUrl(), fullBmp);
}
};
ErrorListener errorListener = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
viewHolder.thumbnail.setImageResource(R.drawable.ic_launcher);
}
};
this.singleInstance.addToRequestQueue(new CustomImageRequest(Request.Method.GET, item.getThumbnailUrl(), errorListener, headers, imageLoadedListener));
}
アプリケーション サーバーのログは次のように表示されます。
GET /app//photo/rest/singlephoto/?photoId=7 HTTP/1.1" 406 1067
それは 406-- 禁じられているか、そのようなものです。また、Android の LogCat は次のようなエラーを示します: BasicNetwork.PerformRequest: Unexpected response code 406 for https://domain/app/singlephoto?photoId=7
コントローラーまたはクライアント、またはその両方に何か問題がありますか?