我正在通过多部分网络表单上传压缩文件。我正在使用 groovy 和 grails 进行上传,但代码在 Java(带有 spring)中看起来也很相似......
def processUpload(){
def uploadedFile = request.getFile('payload')
String vloc = "";
String filename = ""
if(!uploadedFile.empty){
InputStream is = uploadedFile.getInputStream()
java.util.zip.ZipInputStream zis = new java.util.zip.ZipInputStream(is)
def zipentry = zis.getNextEntry();
while(zipentry!=null){
println zipentry.getName()
if( zipentry.getName().indexOf(".")>0){
amazonS3Service.put (zis, zipentry.getName(), session.uid, ".zyx", zipentry.getSize())
}
zipentry = zis.getNextEntry()
}
}
}
如下amazonS3Service.put
_
String put(inputstream, name, uid, ext, length)
{
String mime = mimeExtensionMap[ext.toLowerCase()]
S3Bucket bucket = makeBucket(uid)
S3Object s3Obj = new S3Object()
s3Obj.setAcl AccessControlList.REST_CANNED_PRIVATE
s3Obj.setContentLength length
s3Obj.setContentType mime
s3Obj.setDataInputStream inputstream
s3Obj.setKey name
s3Obj.setBucketName bucket.getName()
s3.putObject bucket, s3Obj
return name
}
似乎 s3.putObject 存储桶、s3Obj 方法正在关闭我的流,因为我收到了 streamClosed 异常。我需要从 zipfile 中获取 nextentry,因此不应关闭流!
我曾尝试将 byteArrayinputstream 与 zis.getBytes() 一起使用,但即使 getBytes() 也会关闭流!
我有哪些选择?
谢谢