Commit 9c263921 authored by alexm98's avatar alexm98

FileController @Create and @Store. Use the ipfs API client to upload the file...

FileController @Create and @Store. Use the ipfs API client to upload the file to IPFS and remove it from temporary storage.
parent 4007edf0
......@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Cloutier\PhpIpfsApi\IPFS;
use File;
class FileController extends Controller
{
......@@ -83,7 +84,15 @@ class FileController extends Controller
*/
public function store(Request $request)
{
//
$file = $request->file;
$destinationPath = public_path().'/uploads/';
$file->move($destinationPath,$file->getClientOriginalName());
$hash = $this->ipfs->add($destinationPath.$file->getClientOriginalName());
File::delete($destinationPath.$file->getClientOriginalName());
return redirect('/files/'.$hash);
}
/**
......@@ -128,7 +137,7 @@ class FileController extends Controller
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy($hash)
{
//
}
......
......@@ -6,10 +6,10 @@
"type": "project",
"require": {
"php": ">=7.0.0",
"cloutier/php-ipfs-api": "0.0.6",
"fideloper/proxy": "~3.3",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0",
"cloutier/php-ipfs-api": "0.0.6"
"laravel/tinker": "~1.0"
},
"require-dev": {
"filp/whoops": "~2.0",
......
This diff is collapsed.
......@@ -3,5 +3,11 @@
@section('content')
<div class="col-md-5">
<h3>Upload a file</h3>
<form method="POST" action="/files" enctype="multipart/form-data">
{{ csrf_field() }}
<br>
<input name="file" type="file"/>
<button type="submit" class="btn btn-success pull-right">Submit</button>
</form>
</div>
@stop
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment