Commit 1380226 1 parent f104636 commit 1380226 Copy full SHA for 1380226
File tree 1 file changed +14
-3
lines changed
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 40
40
* @apiGroup Files
41
41
* @apiDescription Upload file(s) via multipart data upload
42
42
*
43
- * @apiSuccess (204 ) FileUploaded File uploaded
43
+ * @apiSuccess (201 ) FileUploaded File uploaded
44
44
* @apiError (400) NoFileSent No file was sent
45
45
* @apiError (400) FileSizeExceeded Exceeded file size limit
46
46
* @apiError (400) FileNameError Exceeded file name limit
47
47
* @apiError (500) InternalError
48
48
* @apiError (500) UploadException
49
+ *
50
+ * @apiSuccessExample Success-Response:
51
+ * HTTP/1.1 201 OK
52
+ * {
53
+ * "filename": "supercat.png",
54
+ * "directory": "static\/files"
55
+ * }
49
56
*/
50
57
$ router ->post ('/upload ' , function ($ req , $ res ) use ($ app , $ fs ) {
51
58
$ config = $ app ['config ' ];
114
121
}
115
122
116
123
// Name should be unique // TODO
124
+ $ filename = $ basename . '. ' . $ ext ;
117
125
if (!move_uploaded_file (
118
126
$ file ['tmp_name ' ],
119
- sprintf ( ' %s/%s.%s ' , _UPLOADS_ , $ basename , $ ext )
127
+ _UPLOADS_ . $ filename
120
128
)) {
121
129
throw new RuntimeException ('Failed to move uploaded file ' );
122
130
}
128
136
]);
129
137
}
130
138
131
- return $ res ->sendStatus (204 );
139
+ return $ res ->status (201 )->send ([
140
+ 'filename ' => $ filename ,
141
+ 'directory ' => _UPLOADS_
142
+ ]);
132
143
});
133
144
134
145
/**
You can’t perform that action at this time.
0 commit comments