|
11 | 11 | * See the License for the specific language governing permissions and |
12 | 12 | * limitations under the License. |
13 | 13 | **/ |
| 14 | +use Illuminate\Http\Response; |
14 | 15 | use Illuminate\Routing\Controller as BaseController; |
15 | 16 | use Illuminate\Http\JsonResponse; |
16 | 17 | use Illuminate\Support\Facades\Config; |
| 18 | +use OpenApi\Attributes as OA; |
17 | 19 | use Pion\Laravel\ChunkUpload\Exceptions\UploadFailedException; |
18 | 20 | use Illuminate\Support\Facades\Storage; |
19 | 21 | use Illuminate\Http\Request; |
|
28 | 30 | */ |
29 | 31 | class UploadController extends BaseController |
30 | 32 | { |
31 | | - /** |
32 | | - * Handles the file upload |
33 | | - * |
34 | | - * @param Request $request |
35 | | - * |
36 | | - * @return JsonResponse |
37 | | - * |
38 | | - * @throws UploadMissingFileException |
39 | | - * @throws UploadFailedException |
40 | | - */ |
| 33 | + #[OA\Post( |
| 34 | + path: '/api/v1/files/upload', |
| 35 | + summary: 'Upload file with chunked support', |
| 36 | + description: 'Handles file uploads with support for chunked uploads. Returns file metadata on completion or upload progress for chunks.', |
| 37 | + security: [['bearer' => []]], |
| 38 | + tags: ['files'], |
| 39 | + requestBody: new OA\RequestBody( |
| 40 | + required: true, |
| 41 | + content: new OA\MediaType( |
| 42 | + mediaType: 'multipart/form-data', |
| 43 | + schema: new OA\Schema( |
| 44 | + required: ['file'], |
| 45 | + properties: [ |
| 46 | + new OA\Property( |
| 47 | + property: 'file', |
| 48 | + type: 'string', |
| 49 | + format: 'binary', |
| 50 | + description: 'File to upload' |
| 51 | + ), |
| 52 | + ] |
| 53 | + ) |
| 54 | + ) |
| 55 | + ), |
| 56 | + responses: [ |
| 57 | + new OA\Response( |
| 58 | + response: Response::HTTP_OK, |
| 59 | + description: 'File uploaded successfully or chunk progress', |
| 60 | + content: new OA\JsonContent( |
| 61 | + oneOf: [ |
| 62 | + new OA\Schema(ref: '#/components/schemas/FileUploadCompleteResponse'), |
| 63 | + new OA\Schema(ref: '#/components/schemas/FileUploadProgressResponse'), |
| 64 | + ] |
| 65 | + ) |
| 66 | + ), |
| 67 | + new OA\Response(response: Response::HTTP_BAD_REQUEST, description: 'Bad Request'), |
| 68 | + new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: 'Unauthorized'), |
| 69 | + new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: 'Server Error'), |
| 70 | + ] |
| 71 | + )] |
41 | 72 | public function upload(Request $request) { |
42 | 73 | // create the file receiver |
43 | 74 | $receiver = new FileReceiver("file", $request, HandlerFactory::classFromRequest($request)); |
|
0 commit comments