-1
Amazon S3サーバからgif形式とjpeg形式で画像をダウンロードしようとしています。 gif形式で画像をダウンロードしようとすると、画像がZip形式でダウンロードされますが、最初のフレームのみが表示されます(gifには3つの画像が含まれています) 。私は非常に多くの例を見てきましたが、適切な解決策を見つけることができません。読み込みと書き込みgif画像
注:
私が直接画像URLに当たったとき、それはgifまたはgif formateの画像を表示します。ここで
は私のコードです:事前に感謝
@RequestMapping(value={"/downloadPhotographs"}, method=RequestMethod.GET)
public void downloadPhotograph(HttpServletRequest request, HttpServletResponse response, @RequestParam String campaignId, @RequestParam String campaignName) {
String url = "https://s3.amazonaws.com/myimages/"; //not real url
String imageOldId = "";
String img_ext = request.getSession().getAttribute("imgExt").toString();
campaignName = campaignName.replace(" ", "") + "_photographs";
try {
File zipFile = new File("zipdemo.zip");
// create byte buffer
byte[] buffer = new byte[3074];
/*
* To create a zip file, use
* ZipOutputStream(OutputStream out) constructor of ZipOutputStream class.
*/
// create object of FileOutputStream
FileOutputStream fout = new FileOutputStream(zipFile);
// create object of ZipOutputStream from FileOutputStream
ZipOutputStream zout = new ZipOutputStream(fout);
ArrayList<String> imageIdList = downloadUserDataJavaBean.getPhotographsLink(campaignId);
Iterator<String> itr = imageIdList.iterator();
while (itr.hasNext()) {
imageOldId = itr.next();
System.out.println("imgId " + imageOldId);
BufferedImage bufferImage = ImageIO.read(new URL(url + imageOldId + "." + img_ext));
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bufferImage, img_ext, os);
buffer = os.toByteArray();
InputStream is = new ByteArrayInputStream(buffer);
// create object of FileInputStream for source file
// below me
// FileInputStream fin = new FileInputStream(sourceFiles[i]);
/*
* To begin writing ZipEntry in the zip file, use
* void putNextEntry(ZipEntry entry) method of ZipOutputStream
* class.
* This method begins writing a new Zip entry to the zip file
* and positions the stream to the start of the entry data.
*/
zout.putNextEntry(new ZipEntry(imageOldId + "." + img_ext));
/*
* After creating entry in the zip file, actually write the
* file.
*/
int length;
while ((length = is.read(buffer)) > 0) {
zout.write(buffer, 0, length);
}
/*
* After writing the file to ZipOutputStream, use
* void closeEntry() method of ZipOutputStream class to close
* the current entry and position the stream to write the next
* entry.
*/
zout.closeEntry();
// close the InputStream
is.close();
}
// close the ZipOutputStream
zout.close();
System.out.println("Zip file has been created!");
String contentType = "application/excel";
response.setContentType(contentType);
byte[] b = new byte[(int) zipFile.length()];
FileInputStream fis = null;
try {
fis = new FileInputStream(zipFile);
fis.read(b);
fis.close();
} catch (Exception e) {
System.out.println("Problem in file input stream" + e.toString());
}
response.setHeader("Content-Disposition", "attachment; filename=" + campaignName + ".zip");
response.setContentLength(b.length);
response.getOutputStream().write(b);
response.getOutputStream().flush();
response.getOutputStream().close();
} catch (IOException ioe) {
System.out.println("IOException :" + ioe);
}
}