@@ -977,18 +977,40 @@ function userApikeyDefault($args)
977977 return array ('apikey ' => $ defaultApiKey );
978978 }
979979
980+ /**
981+ * Download a bitstream either by its id or by a checksum. Either an id or checksum parameter is required.
982+ * @param token (Optional) Authentication token
983+ * @param id (Optional) The id of the bitstream
984+ * @param checksum (Optional) The checksum of the bitstream
985+ * @param name (Optional) Alternate filename to download as
986+ */
980987 function bitstreamDownload ($ args )
981988 {
982- $ this ->_validateParams ($ args , array ('id ' ));
989+ if (!array_key_exists ('id ' , $ args ) && !array_key_exists ('checksum ' , $ args ))
990+ {
991+ throw new Exception ('Either an id or checksum parameter is required ' , MIDAS_INVALID_PARAMETER );
992+ }
983993 $ userDao = $ this ->_getUser ($ args );
984994 $ modelLoader = new MIDAS_ModelLoader ();
985995 $ bitstreamModel = $ modelLoader ->loadModel ('Bitstream ' );
986- $ bitstream = $ bitstreamModel ->load ($ args ['id ' ]);
996+ if (array_key_exists ('id ' , $ args ))
997+ {
998+ $ bitstream = $ bitstreamModel ->load ($ args ['id ' ]);
999+ }
1000+ else
1001+ {
1002+ $ bitstream = $ bitstreamModel ->getByChecksum ($ args ['checksum ' ]);
1003+ }
9871004
9881005 if (!$ bitstream )
9891006 {
9901007 throw new Exception ('Invalid bitstream id ' , MIDAS_INVALID_PARAMETER );
9911008 }
1009+
1010+ if (array_key_exists ('name ' , $ args ))
1011+ {
1012+ $ bitstream ->setName ($ args ['name ' ]);
1013+ }
9921014 $ revisionModel = $ modelLoader ->loadModel ('ItemRevision ' );
9931015 $ revision = $ revisionModel ->load ($ bitstream ->getItemrevisionId ());
9941016
0 commit comments