Commit 75e191c9 authored by 康帅杰's avatar 康帅杰 :speech_balloon:
Browse files

1.0.0

parents
No related merge requests found
Showing with 206 additions and 0 deletions
+206 -0
{
"name": "Yjtec/laravel-upload",
"description": "laravel update controllerr migration mode",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "kidkang",
"email": "723616880@qq.com"
}
],
"minimum-stability": "dev",
"require": {},
"autoload": {
"psr-4": {
"Yjtec\\Upload\\":"src/"
}
},
"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.laravel-china.org"
}
},
"extra": {
"laravel": {
"providers": [
"Yjtec\\Upload\\UploadServiceProvider"
]
}
}
}
<?php
namespace Yjtec\Upload\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Storage;
class IndexController extends Controller
{
public function index(Request $request)
{
echo 333;
}
/**
* @OA\Post(
* path="/kd/upload",
* tags={"Upload"},
* summary="上传接口",
* operationId="uploadUpload",
* @OA\Response(
* response=200,
* description="pet response",
* @OA\JsonContent(ref="#/components/schemas/Error")
* ),
* @OA\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* @OA\Property(
* property="file",
* description="上传文件字段名",
* type="file"
* ),
* @OA\Property(
* property="path",
* description="文件存储的路径",
* type="string"
* ),
* @OA\Property(
* property="foreign_key",
* description="文件的唯一建值",
* type="string"
* ),
* )
*
* )
* ),
* security={
* {"token": {}}
* }
* )
*/
public function upload(Request $request)
{
$filepath = $request->input('path');
$foreign_key = $request->input('foreign_key');
$path = $request->file('file')->store($filepath);
$url = Storage::url($path);
$inser = [
'filename' => $request->file->getClientOriginalName(),
'mimetype' => $request->file->getClientMimeType(),
'filesize' => $request->file->getClientSize(),
'extension' => $request->file->guessClientExtension(),
'path' => $filepath,
'url' => $url,
'foreign_key' => $foreign_key,
];
$file = \Kd\Upload\Models\File::create($inser);
return [
'url' => $url,
'path' => $path,
'file_id' => $file->id
];
}
}
<?php
namespace Yjtec\Upload\Models;
use Illuminate\Database\Eloquent\Model;
class File extends Model
{
//
protected $table="file_system";
protected $fillable = [
'filename', 'mimetype', 'filesize', 'extension','path','url','foreign_key'
];
}
<?php
namespace Yjtec\Upload;
use Illuminate\Support\ServiceProvider;
class UploadServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$this->loadMigrationsFrom(__DIR__.'/database/migrations');
$this->loadRoutesFrom(__DIR__.'/routes.php');
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/config.php', 'upload'
);
}
}
<?php
return [
'api_prefix' => env('UPLOAD_URI_PREFIX','/api/V1/')
];
\ No newline at end of file
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateFileTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('file_system', function (Blueprint $table) {
$table->increments('id');
$table->string('filename',255)->comment('文件名称');
$table->string('mimetype',100)->comment('文件mimetype');
$table->integer('filesize')->comment('文件大小');
$table->string('extension',20)->comment('文件后缀名');
$table->string('path',255)->comment('相对路径');
$table->string('url',500)->comment('文件的url');
$table->integer('foreign_key')->nullable()->default(0)->comment('文件关联的外部主键');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('file_system');
}
}
<?php
Route::get('/kd/upload', function () {
echo 'uplaod test';
});
Route::prefix(config('upload.api_prefix'))->get('/kd/controller', 'Kd\Upload\Controllers\IndexController@index');
Route::prefix(config('upload.api_prefix'))->post('/kd/upload', 'Kd\Upload\Controllers\IndexController@upload');
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