File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 4040 * @apiGroup Files
4141 * @apiDescription Upload file(s) via multipart data upload
4242 *
43- * @apiSuccess (204 ) FileUploaded File uploaded
43+ * @apiSuccess (201 ) FileUploaded File uploaded
4444 * @apiError (400) NoFileSent No file was sent
4545 * @apiError (400) FileSizeExceeded Exceeded file size limit
4646 * @apiError (400) FileNameError Exceeded file name limit
4747 * @apiError (500) InternalError
4848 * @apiError (500) UploadException
49+ *
50+ * @apiSuccessExample Success-Response:
51+ * HTTP/1.1 201 OK
52+ * {
53+ * "filename": "supercat.png",
54+ * "directory": "static\/files"
55+ * }
4956 */
5057$ router ->post ('/upload ' , function ($ req , $ res ) use ($ app , $ fs ) {
5158 $ config = $ app ['config ' ];
114121 }
115122
116123 // Name should be unique // TODO
124+ $ filename = $ basename . '. ' . $ ext ;
117125 if (!move_uploaded_file (
118126 $ file ['tmp_name ' ],
119- sprintf ( ' %s/%s.%s ' , _UPLOADS_ , $ basename , $ ext )
127+ _UPLOADS_ . $ filename
120128 )) {
121129 throw new RuntimeException ('Failed to move uploaded file ' );
122130 }
128136 ]);
129137 }
130138
131- return $ res ->sendStatus (204 );
139+ return $ res ->status (201 )->send ([
140+ 'filename ' => $ filename ,
141+ 'directory ' => _UPLOADS_
142+ ]);
132143});
133144
134145/**
You can’t perform that action at this time.
0 commit comments