X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fapimediaupload.php;h=fedaef17482076e29bb75f5d3542724c87f087c4;hb=9728270acd45069f3d56e8b9f2e3988bdcf4fc96;hp=0b08dbedf1bc1dec517b0e8e26307ca1e9e4d280;hpb=04ae500749ea2e5937ac1f28ef8c7edf4f99f0a1;p=quix0rs-gnu-social.git diff --git a/actions/apimediaupload.php b/actions/apimediaupload.php index 0b08dbedf1..fedaef1748 100644 --- a/actions/apimediaupload.php +++ b/actions/apimediaupload.php @@ -26,12 +26,7 @@ * @link http://status.net/ */ -if (!defined('STATUSNET')) { - exit(1); -} - -require_once INSTALLDIR . '/lib/apiauth.php'; -require_once INSTALLDIR . '/lib/mediafile.php'; +if (!defined('GNUSOCIAL')) { exit(1); } /** * Upload an image via the API. Returns a shortened URL for the image @@ -45,6 +40,8 @@ require_once INSTALLDIR . '/lib/mediafile.php'; */ class ApiMediaUploadAction extends ApiAuthAction { + protected $needPost = true; + /** * Handle the request * @@ -56,18 +53,9 @@ class ApiMediaUploadAction extends ApiAuthAction * * @return void */ - function handle($args) + protected function handle() { - parent::handle($args); - - if ($_SERVER['REQUEST_METHOD'] != 'POST') { - $this->clientError( - // TRANS: Client error. POST is a HTTP command. It should not be translated. - _('This method requires a POST.'), - 400, $this->format - ); - return; - } + parent::handle(); // Workaround for PHP returning empty $_POST and $_FILES when POST // length > post_max_size in php.ini @@ -82,41 +70,31 @@ class ApiMediaUploadAction extends ApiAuthAction 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.', intval($_SERVER['CONTENT_LENGTH'])); $this->clientError(sprintf($msg, $_SERVER['CONTENT_LENGTH'])); - return; } - $upload = null; - - try { - $upload = MediaFile::fromUpload('media', $this->auth_user); - } catch (Exception $e) { - $this->clientError($e->getMessage(), $e->getCode()); - return; - } + // we could catch "NoUploadedMediaException" as "no media uploaded", but here we _always_ want an upload + $upload = MediaFile::fromUpload('media', $this->scoped); + + // Thumbnails will be generated/cached on demand when accessed (such as with /attachment/:id/thumbnail) - if (isset($upload)) { - $this->showResponse($upload); - } else { - // TRANS: Client error displayed when uploading a media file has failed. - $this->clientError(_('Upload failed.')); - return; - } + $this->showResponse($upload); } /** * Show a Twitpic-like response with the ID of the media file * and a (hopefully) shortened URL for it. * - * @param File $upload the uploaded file + * @param MediaFile $upload the uploaded file * * @return void */ - function showResponse($upload) + function showResponse(MediaFile $upload) { $this->initDocument(); $this->elementStart('rsp', array('stat' => 'ok')); $this->element('mediaid', null, $upload->fileRecord->id); $this->element('mediaurl', null, $upload->shortUrl()); + $this->element('mediahref', null, $upload->fileRecord->getUrl()); $this->elementEnd('rsp'); $this->endDocument(); } @@ -137,5 +115,6 @@ class ApiMediaUploadAction extends ApiAuthAction $this->element('err', $errAttr, null); $this->elementEnd('rsp'); $this->endDocument(); + exit; } }