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