【问题标题】:Waiting for file to upload before sending to S3?在发送到 S3 之前等待文件上传?
【发布时间】:2014-02-10 10:07:21
【问题描述】:

我在 Appfog 上使用 Laravel 将较大的文件上传到 Amazon S3 时遇到问题。

对于 1kb 到 1.5Mb 之间的文件,它工作得非常好。 但是再大一点,它就会失败。

原因似乎是服务器在文件实际上传并在服务器内存中之前显然正在触发 S3 上传代码。

因为错误信息是 S3 Laravel Bundle 返回的未处理异常...

说……

   S3::inputFile(): Unable to open input file: 

当我通过 wamp 在本地使用相同的文件上传/运行此功能时,它工作得很好。并完美实现 S3。

只有当文件通过线路传输到我的 appfog 应用程序时,它才会中断。因为本地上传需要20ms,而通过wire上传大约需要4秒。

这表明它显然在文件到达之前触发了代码或类似的东西。

再一次,当文件很小时,它在我的应用程序中运行得非常好。只有当它们大一点时它才会破裂。

有什么想法吗???

public function action_uploadfile(){
    $input = Input::all();

    if(!empty($input['theDoc']['name'])){

        $file = Input::file('theDoc');
        $s = Setting::shortcode();
        $id = $input['theID']."-".$input['leadID'];
        $path_parts = pathinfo($file['name']);
        $ext = $path_parts['extension'];

            if(!empty($input['theName'])){
                $filename = $input['theName'].".".$ext;
            } else {
                $filename = $file['name'];
            }

            if((!empty($file))&&(S3::inputFile($file['tmp_name'], false))){

                if(S3::putObject($input2, 'myAMAZONBucket', $s."/".$id."/".$filename, S3::ACL_PUBLIC_READ)){
                $file2 = Doc::where('uri','=', $s."/".$id."/".$filename)->get();
                if($file2){
                  // duplicate file/document error goes here
                } else {
                    $f = New Doc;
                    $f->lead_id = $input['leadID'];
                    $f->sale_id = $input['theID'];
                    $f->user_id = Auth::user()->id;
                    $f->notes = $input['theNotes'];
                    $f->filetype = $ext;
                    $f->filesize = $file['size'];
                    $f->filename = $filename;
                    $f->uri = $s."/".$id."/".$filename;
                    if($f->save()){
                     return Redirect::back();
                    };
                }
            } else {
                 //Cannot read file error
            }

            } else {
                 //Failed upload error
            }

        } else {
           //No file selected error
        }
}

【问题讨论】:

    标签: file-upload amazon-s3 laravel laravel-3 appfog


    【解决方案1】:

    尝试使用一些 ini_set() 来处理 max_execution_time 和 set_time_limit 之类的东西,看看其中一个是否设置得太低。

    【讨论】:

    • 你这么说很有趣......因为我在本地机器上的 max_execution_time 是 30 秒,而在有问题的服务器上,它是 300 秒......我不明白它???
    猜你喜欢
    • 2021-07-23
    • 1970-01-01
    • 2016-09-21
    • 1970-01-01
    • 1970-01-01
    • 2017-12-14
    • 2022-11-12
    • 2019-02-19
    • 2018-09-25
    相关资源
    最近更新 更多