Android s3 SDK:使用TransferManager类上传大文件失败

时间:2011-08-12 07:17:21

标签: android amazon-s3 sax

我们有几个广泛使用S3的Android应用。我们使用Android SDK中的TranferManager类将文件上传到S3。它说:“E / HttpClient(6081):com.amazonaws.AmazonClientException:无法初始化XMLReader的sax驱动程序”

我们尝试过使用0.1.0和0.2.1版本的SDK,两者都在大型(200MB +)上传时遇到同样的问题。

以下是我们的代码段:

ObjectMetadata attMetaData = new ObjectMetadata();
attMetaData.setContentLength(attachment.getFileSize());                                                                                             
TransferManager tm = new TransferManager(Utility.getInstance().getAWSInstance(OutboxService.this));
Transfer myUpload = tm.upload(Constants.S3.BUCKET, Attachment.mediaFolders.get(attachment.getFileType())+ attachment.getFileName(), is, attMetaData);

异常日志是:

W/HttpMethodBase( 6081): Going to buffer response body of large or unknown size. Using   getResponseBodyAsStream instead is recommended.
D/dalvikvm( 6081): GC_FOR_MALLOC freed 10875 objects / 636320 bytes in 61ms
D/NativeCrypto( 6081): Freeing OpenSSL session
D/NativeCrypto( 6081): Freeing OpenSSL session
E/HttpClient( 6081): Unable to unmarshall response (Couldn't initialize a sax driver for the XMLReader): <?xml version="1.0" encoding="UTF-8"?>
E/HttpClient( 6081): <InitiateMultipartUploadResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Bucket>ltd_avmessaging</Bucket><Key>videos/2498992-1313049697.3gp</Key>  <UploadId>Tv397TYchM_.U_JDE7PyQcF21lyrtQ7jZYoFG08PgRt07YPn6f_LxlRHVSneGxfdFkGktBs9bIBCA.hAdRb88g--</UploadId></InitiateMultipartUploadResult>
E/HttpClient( 6081): com.amazonaws.AmazonClientException: Couldn't initialize a sax driver for the XMLReader
E/HttpClient( 6081):  at com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser.<init>(Unknown Source)
E/HttpClient( 6081):  at   com.amazonaws.services.s3.model.transform.Unmarshallers$InitiateMultipartUploadResultUnmarshaller.unmarshall(Unknown Source)
E/HttpClient( 6081):  at com.amazonaws.services.s3.model.transform.Unmarshallers$InitiateMultipartUploadResultUnmarshaller.unmarshall(Unknown Source)
E/HttpClient( 6081):  at com.amazonaws.services.s3.internal.S3XmlResponseHandler.handle(Unknown Source)
E/HttpClient( 6081):  at com.amazonaws.services.s3.internal.S3XmlResponseHandler.handle(Unknown Source)
E/HttpClient( 6081):  at com.amazonaws.http.HttpClient.handleResponse(Unknown Source)
E/HttpClient( 6081):  at com.amazonaws.http.HttpClient.executeHelper(Unknown Source)
E/HttpClient( 6081):  at com.amazonaws.http.HttpClient.execute(Unknown Source)
E/HttpClient( 6081):  at com.amazonaws.services.s3.AmazonS3Client.initiateMultipartUpload(Unknown Source)
E/HttpClient( 6081):  at com.amazonaws.services.s3.transfer.internal.MultipartUploadCallable.initiateMultipartUpload(Unknown Source)
E/HttpClient( 6081):  at com.amazonaws.services.s3.transfer.internal.MultipartUploadCallable.call(Unknown Source)
E/HttpClient( 6081):  at com.amazonaws.services.s3.transfer.internal.MultipartUploadCallable.call(Unknown Source)
E/HttpClient( 6081):  at com.amazonaws.services.s3.transfer.internal.TransferStateUpdatingCallable.call(Unknown Source)
E/HttpClient( 6081):  at com.amazonaws.services.s3.transfer.internal.TransferStateUpdatingCallable.call(Unknown Source)
E/HttpClient( 6081):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
E/HttpClient( 6081):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)

E / HttpClient(6081):at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)     E / HttpClient(6081):at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:561)     E / HttpClient(6081):在java.lang.Thread.run(Thread.java:1102)

1 个答案:

答案 0 :(得分:0)

通过设置以下系统属性,使用S3时似乎可以解决很多这些SAX解析器错误。

  

System.setProperty(“org.xml.sax.driver”,“org.xmlpull.v1.sax2.Driver”);

(取自https://forums.aws.amazon.com/thread.jspa?messageID=251760&#251760