如何解决我正在尝试使用laravel将文件上传到保管箱
我正在尝试使用laravel将文件上传到保管箱。我按照我在文档中阅读的步骤进行操作,但是没有得到。
我安装了Dropbox适配器,然后,我将提供程序创建为文档中的名称,并将代码也放置在文档中
提供者:
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\Filesystem;
use Spatie\Dropbox\Client as DropboxClient;
use Spatie\FlysystemDropbox\DropboxAdapter;
class DropboxServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Storage::extend('dropbox',function ($app,$config) {
$client = new DropboxClient(
$config['authorization_token']
);
return new Filesystem(new DropboxAdapter($client));
});
}
}
我创建了磁盘的文件系统中
'dropbox' => [
'driver' => 'dropbox','authorization_token' => env('DROPBOX_TOKEN'),],
在应用程序中,我添加了以下行
// Dropbox
App\Providers\DropboxServiceProvider::class,
在环境中我添加了以下几行。访问令牌和应用程序密码来自在保管箱中创建的api
DROPBOX_TOKEN = <REDACTED>
DROPBOX_SECRET = <REDACTED>
查看:
<div>
<form action="{{ route('uploadStore') }}" enctype="multipart/form-data" method="post">
@csrf
<input type="file" name="image">
<br>
<input type="submit" value="Enviar">
</form>
</div>
<div>
@if($errors->any())
<h4>{{$errors->first()}}</h4>
@endif
</div>
和控制器:
protected function index() {
$files = Storage::allFiles('teste-gobsruiz01');
return view('index',[
'files' => $files,]);
}
protected function store(Request $request) {
$file = $request->file("image");
$is_file_uploaded = Storage::disk('dropbox')->put('teste-gobsruiz01',$file);
if($is_file_uploaded){
return Redirect::back()->withErrors(['msg'=>'Succesfuly file uploaded to dropbox']);
} else {
return Redirect::back()->withErrors(['msg'=>'file failed to uploaded on dropbox']);
}
}
我在保管箱中创建了api。名称是teste-gobsruiz01。我还创建了两条路线,即get和post。
如果有人可以帮助我,我表示感谢。我已经尝试了很长时间了
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。