/**
* Upload an image via the API. Returns a shortened URL for the image
- * to the user.
+ * to the user. Apparently modelled after a former Twitpic API.
*
* @category API
* @package StatusNet
// we could catch "NoUploadedMediaException" as "no media uploaded", but here we _always_ want an upload
$upload = MediaFile::fromUpload('media', $this->scoped);
-
- // Hack to make a thumbnail before giving back a response
- // (the file should instead actually be attached to a notice in the file_to_post table)
- try {
- if ($upload->fileRecord instanceof File) {
- $upload->fileRecord->getThumbnail();
- }
- } catch (Exception $e) {
- common_debug(sprintf('A hack is buggy: MediaFile fileRecord could not getThumbnail for file id==%u',
- $upload->fileRecord->id));
- }
+
+ // Thumbnails will be generated/cached on demand when accessed (such as with /attachment/:id/thumbnail)
$this->showResponse($upload);
}
function showResponse(MediaFile $upload)
{
$this->initDocument();
- $this->elementStart('rsp', array('stat' => 'ok'));
+ $this->elementStart('rsp', array('stat' => 'ok', 'xmlns:atom'=>Activity::ATOM));
$this->element('mediaid', null, $upload->fileRecord->id);
$this->element('mediaurl', null, $upload->shortUrl());
+
+ $enclosure = $upload->fileRecord->getEnclosure();
+ $this->element('atom:link', array('rel' => 'enclosure',
+ 'href' => $enclosure->url,
+ 'type' => $enclosure->mimetype));
$this->elementEnd('rsp');
$this->endDocument();
}
*
* @param String $msg an error message
*/
- function clientError($msg)
+ function clientError($msg, $code=400, $format=null)
{
$this->initDocument();
$this->elementStart('rsp', array('stat' => 'fail'));
$this->element('err', $errAttr, null);
$this->elementEnd('rsp');
$this->endDocument();
+ exit;
}
}