使用Play框架上传多个文件时,2 MB文件上传到AWS S3失败

时间:2013-06-13 21:56:13

标签: scala amazon-s3 playframework-2.0 scala-2.8

我收到此错误,并不确定其实际领先地位。当我尝试上传100 KB的文件时;它很好地上传到S3,但是对于一个2MB的文件,它失败了没有严重的异常,但是这个:

[trace] play - Sending simple result: SimpleResult(200, Map(Content-Type -> text/html;    charset=utf-8, Set-Cookie -> ))
[trace] application - Exception caught in Netty
java.lang.ClassCastException: scala.runtime.BoxedUnit cannot be cast to scala.Function0
     at     play.core.server.netty.PlayDefaultUpstreamHandler.channelDisconnected(PlayDefaultUpstreamHa n dler.scala:50) ~[play.play_2.10-2.1.0.jar:2.1.0]
    at org.jboss.netty.handler.codec.replay.ReplayingDecoder.cleanup(ReplayingDecoder.java:570) ~[io.netty.netty-3.6.3.Final.jar:na]
    at org.jboss.netty.handler.codec.frame.FrameDecoder.channelDisconnected(FrameDecoder.java:365) ~[io.netty.netty-3.6.3.Final.jar:na]
    at org.jboss.netty.channel.Channels.fireChannelDisconnected(Channels.java:396) ~[io.netty.netty-3.6.3.Final.jar:na]
    at org.jboss.netty.channel.socket.nio.AbstractNioWorker.close(AbstractNioWorker.java:336) ~[io.netty.netty-3.6.3.Final.jar:na]
      at     org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.handleAcceptedSocket(NioServ    erSocketPipelineSink.java:81) ~[io.netty.netty-3.6.3.Final.jar:na]
[trace] play - Http request received by netty: DefaultHttpRequest(chunked: false)
GET /favicon.ico HTTP/1.0
X-Real-IP: X.X.X.X
X-Scheme: http
X-Forwarded-For: X.X.X.X, X.X.X.X
Host: 
Connection: close
Accept: */*
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Cookie: s_nr=1369981333181; PLAY_SESSION=f672ed541f895539f476

它甚至没有到达Web服务器并且失败并且抛出了500页未找到错误;因为它完全关闭了连接。

我正在使用Play Framework 2.0并使用AWS S3 HL Multipart上传。我等到我的服务完成上传。

请让我知道可能是什么问题;或任何导致这个?

这是我的代码:

        //Setting expiration time for the files in temp bucket to 24 hours [1 Day]
        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setExpirationTime(DateTime.now().plusDays(1).toDate());
        objectMetadata.setContentLength(UploadData.getFileSize());

        //Setting user data
        userData = new HashMap<>();
        userData.put(UserMetaData.filename.name(), UploadData.getFileName());
        if (!NullChecker.isEmpty(UploadData.getFileSize())) {
            userData.put(UserMetaData.size.name(), String.valueOf(UploadData.getFileSize()));
        }
        if (!NullChecker.isEmpty(UploadData.getSerialNo())) {
            userData.put(UserMetaData.serialno.name(), UploadData.getSerialNo());
        }
        objectMetadata.setUserMetadata(userData);

        // TransferManager processes all transfers asynchronously,
        // so this call will return immediately.
        upload = transferManager.upload(bucketName, key, UploadData.getFileInputStream(), objectMetadata);

        try {
            // Or you can block and wait for the upload to finish
            upload.waitForCompletion();
        } catch (AmazonClientException amazonClientException) {
            logger.info("Unable to upload file, upload was aborted.");
            amazonClientException.printStackTrace();
        }

1 个答案:

答案 0 :(得分:1)

我非常满意我在这里收到的回复[实际上没有];我不确定你们谁都不知道这个问题或者事实上是否有任何意见:但无论如何,它得到了解决,这就是答案:

问题是,在我们的unix机器中,配置了Ngnix,当检查Ngnix错误日志时,发现:

[error] 25556#0: *52 client intended to send too large body:

甚至不允许上传2 MB文件。将配置更改为更大的大小限制后;它开始工作了。下面的代码将帮助您:

php.ini中的更改

将最大文件上传大小更改为100MB

vim /etc/php5/fpm/php.ini

...集

upload_max_filesize = 100M
post_max_size = 100M

谢谢,