Skip to content

Commit 1380226

Browse files
committed
Better response for uploads
1 parent f104636 commit 1380226

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

Parvula/routes/api/files.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,19 @@
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'];
@@ -114,9 +121,10 @@
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
}
@@ -128,7 +136,10 @@
128136
]);
129137
}
130138

131-
return $res->sendStatus(204);
139+
return $res->status(201)->send([
140+
'filename' => $filename,
141+
'directory' => _UPLOADS_
142+
]);
132143
});
133144

134145
/**

0 commit comments

Comments
 (0)