UploadController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Response;
  5. use Illuminate\Support\Str;
  6. class UploadController extends Controller
  7. {
  8. /**
  9. * Display a listing of the resource.
  10. *
  11. * @return Response
  12. */
  13. public function index()
  14. {
  15. //
  16. }
  17. /**
  18. * Store a newly created resource in storage.
  19. *
  20. * @return Response
  21. */
  22. public function store(Request $request)
  23. {
  24. //
  25. $request->validate([
  26. 'file' => 'required',
  27. ]);
  28. $file = $request->file('file');
  29. // Move Uploaded File
  30. if ($request->input('is_tmp', false) == false) {
  31. $bucket = config('mint.attachments.bucket_name.permanent');
  32. } else {
  33. $bucket = config('mint.attachments.bucket_name.temporary');
  34. }
  35. $uploadFilename = Str::uuid().'.'.$file->extension();
  36. $filename = $file->storeAs($bucket, $uploadFilename);
  37. $json = [
  38. 'filename' => $bucket.'/'.$uploadFilename,
  39. 'size' => $file->getSize(),
  40. 'type' => $file->getMimeType(),
  41. 'url' => storage_path('app/'.$filename),
  42. 'uid' => Str::uuid(),
  43. ];
  44. return $this->ok($json);
  45. }
  46. /**
  47. * Display the specified resource.
  48. *
  49. * @param int $id
  50. * @return Response
  51. */
  52. public function show($id)
  53. {
  54. //
  55. }
  56. /**
  57. * Update the specified resource in storage.
  58. *
  59. * @param int $id
  60. * @return Response
  61. */
  62. public function update(Request $request, $id)
  63. {
  64. //
  65. }
  66. /**
  67. * Remove the specified resource from storage.
  68. *
  69. * @param int $id
  70. * @return Response
  71. */
  72. public function destroy($id)
  73. {
  74. //
  75. }
  76. }