@@ 264-274 (lines=11) @@ | ||
261 | $file = Injector::inst()->create($fileClass); |
|
262 | ||
263 | // check canCreate permissions |
|
264 | if (!$file->canCreate(null, $data)) { |
|
265 | $result = ['message' => [ |
|
266 | 'type' => 'error', |
|
267 | 'value' => _t( |
|
268 | 'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.CreatePermissionDenied', |
|
269 | 'You do not have permission to add files' |
|
270 | ) |
|
271 | ]]; |
|
272 | return (new HTTPResponse(json_encode($result), 403)) |
|
273 | ->addHeader('Content-Type', 'application/json'); |
|
274 | } |
|
275 | ||
276 | $uploadResult = $upload->loadIntoFile($tmpFile, $file, $parentRecord ? $parentRecord->getFilename() : '/'); |
|
277 | if (!$uploadResult) { |
|
@@ 277-287 (lines=11) @@ | ||
274 | } |
|
275 | ||
276 | $uploadResult = $upload->loadIntoFile($tmpFile, $file, $parentRecord ? $parentRecord->getFilename() : '/'); |
|
277 | if (!$uploadResult) { |
|
278 | $result = ['message' => [ |
|
279 | 'type' => 'error', |
|
280 | 'value' => _t( |
|
281 | 'SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.LoadIntoFileFailed', |
|
282 | 'Failed to load file' |
|
283 | ) |
|
284 | ]]; |
|
285 | return (new HTTPResponse(json_encode($result), 400)) |
|
286 | ->addHeader('Content-Type', 'application/json'); |
|
287 | } |
|
288 | ||
289 | $file->ParentID = $parentRecord ? $parentRecord->ID : 0; |
|
290 | $file->write(); |