【发布时间】: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