Continue work on FileUpload. Created FileController

This commit is contained in:
Torsten 2020-02-05 17:04:01 +01:00
parent b93f0254a6
commit 0263c0f838
5 changed files with 69 additions and 7 deletions

View file

@ -2,12 +2,11 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="eed7de89-f054-487c-bf59-36356758942b" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/resources/js/views/Upload.vue" afterDir="false" />
<change afterPath="$PROJECT_DIR$/app/Http/Controllers/FileController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/public/js/Icon.js" beforeDir="false" afterPath="$PROJECT_DIR$/public/js/Icon.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/public/js/app.js" beforeDir="false" afterPath="$PROJECT_DIR$/public/js/app.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/js/routes.js" beforeDir="false" afterPath="$PROJECT_DIR$/resources/js/routes.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/js/views/Main.vue" beforeDir="false" afterPath="$PROJECT_DIR$/resources/js/views/Main.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/js/views/Upload.vue" beforeDir="false" afterPath="$PROJECT_DIR$/resources/js/views/Upload.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/routes/api.php" beforeDir="false" afterPath="$PROJECT_DIR$/routes/api.php" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -234,7 +233,8 @@
<workItem from="1580650898570" duration="4205000" />
<workItem from="1580726763967" duration="4887000" />
<workItem from="1580891513768" duration="68000" />
<workItem from="1580891625747" duration="947000" />
<workItem from="1580891625747" duration="1061000" />
<workItem from="1580916835678" duration="1719000" />
</task>
<servers />
</component>
@ -263,10 +263,15 @@
</state>
<state x="629" y="273" key="#com.intellij.openapi.updateSettings.impl.PluginUpdateInfoDialog/0.0.1920.1080@0.0.1920.1080" timestamp="1580564280549" />
<state x="419" y="219" key="#com.intellij.openapi.updateSettings.impl.PluginUpdateInfoDialog/0.23.1280.777@0.23.1280.777" timestamp="1580891589354" />
<state x="450" y="179" key="SettingsEditor" timestamp="1580731664075">
<screen x="0" y="0" width="1920" height="1080" />
<state x="1978" y="315" key="#com.jetbrains.php.actions.copyPaste.importReferences.PhpImportReferencesDialog" timestamp="1580917019448">
<screen x="1280" y="23" width="1920" height="1057" />
</state>
<state x="1978" y="315" key="#com.jetbrains.php.actions.copyPaste.importReferences.PhpImportReferencesDialog/0.23.1280.777/1280.23.1920.1057@1280.23.1920.1057" timestamp="1580917019448" />
<state x="1730" y="198" key="SettingsEditor" timestamp="1580917895369">
<screen x="1280" y="23" width="1920" height="1057" />
</state>
<state x="450" y="179" key="SettingsEditor/0.0.1920.1080@0.0.1920.1080" timestamp="1580731664075" />
<state x="1730" y="198" key="SettingsEditor/0.23.1280.777/1280.23.1920.1057@1280.23.1920.1057" timestamp="1580917895369" />
<state x="1280" y="23" width="1720" height="857" maximized="true" key="com.intellij.history.integration.ui.views.FileHistoryDialog" timestamp="1580282545601">
<screen x="1280" y="23" width="1920" height="1057" />
</state>

View file

@ -0,0 +1,37 @@
<?php
namespace App\Http\Controllers;
use App\Pagecontents;
use Illuminate\Http\Request;
use Log;
class FileController extends Controller
{
public function upload(Request $request) {
Log::info("Request:");
Log::info($request);
$exploded = explode(',', $request->image);
Log::info("exploded:");
Log::info($exploded);
$decoded = base64_decode($exploded[1]);
if(str_contains($exploded[0],’jpeg’)) {
$extension = 'jpg';
} else {
$extension = 'png';
}
$fileName=str_random().'.'.$extension;
$path = public_path().'/'.$fileName;
file_put_contents($path, $decoded);
Log::info("Upload endpoint reached.");
Log::info("Filename:".$fileName);
return response()->json([], 200);
}
}

View file

@ -2181,6 +2181,15 @@ __webpack_require__.r(__webpack_exports__);
onFileSelected: function onFileSelected(event) {
console.log("File changed:");
console.log(event.target.files[0].name);
var fd = new FormData();
fd.append('image', event.target.files[0], event.target.files[0].name);
axios.post('http://localhost:8000/api/v1/auth/upload', fd, {
headers: {
'Authorization': 'Bearer ' + this.$store.state.user_token
}
}).then(function (res) {
console.log(res);
});
}
}
});

View file

@ -125,6 +125,16 @@
onFileSelected(event) {
console.log("File changed:");
console.log(event.target.files[0].name);
const fd = new FormData();
fd.append('image',event.target.files[0],event.target.files[0].name);
axios.post('http://localhost:8000/api/v1/auth/upload',fd,{
headers: {
'Authorization': 'Bearer ' + this.$store.state.user_token
}
})
.then(res=>{
console.log(res);
})
}
}
}

View file

@ -49,6 +49,7 @@ Route::prefix('v1')->group(function () {
Route::post('set_role','AuthController@set_role');
Route::post('delete_user','AuthController@delete_user');
Route::post('upload','FileController@upload');
});
});
});