Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 517662d

Browse files
committed
ENH: refs #0306. Make Httpupload component the same as kwupload api
Java uploader will now use the same logic that the web api uploads use, including streaming md5
1 parent b42132d commit 517662d

File tree

2 files changed

+211
-102
lines changed

2 files changed

+211
-102
lines changed

core/controllers/UploadController.php

Lines changed: 79 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function javauploadAction()
162162

163163
$parent = $this->_getParam('parent');
164164
$license = $this->_getParam('license');
165-
if(!empty ($parent) && !empty($license))
165+
if(!empty($parent) && !empty($license))
166166
{
167167
$this->disableView();
168168
$this->userSession->JavaUpload->parent = $parent;
@@ -171,45 +171,106 @@ public function javauploadAction()
171171
}//end java upload
172172

173173

174-
/** used to see how much of a file made it to the server during an
175-
* interrupted upload attempt **/
174+
/**
175+
* Used to see how much of a file made it to the server during an interrupted upload attempt
176+
* @param uploadUniqueIdentifier The upload token to check
177+
*/
176178
function gethttpuploadoffsetAction()
177179
{
178180
$this->disableLayout();
179181
$this->disableView();
180182
$params = $this->_getAllParams();
181-
$url = $this->view->url();
182-
$url = substr($url, 0, strrpos($url, '/'));
183-
$params['internParameter'] = substr($url, strrpos($url, '/') + 1);
184-
$this->Component->Httpupload->get_http_upload_offset($params);
185-
} //end get_http_upload_offset
186183

187-
/** java upload function, didn't check what it does :-) */
184+
list($userId, , ) = explode('/', $params['uploadUniqueIdentifier']);
185+
if($userId != $this->userSession->Dao->getUserId())
186+
{
187+
echo '[ERROR]User id does not match upload token user id';
188+
throw new Zend_Exception('User id does not match upload token user id');
189+
}
190+
191+
$this->Component->Httpupload->setTmpDirectory($this->getTempDirectory());
192+
$this->Component->Httpupload->setTokenParamName('uploadUniqueIdentifier');
193+
$this->Component->Httpupload->getOffset($params);
194+
} //end gethttpuploadoffset
195+
196+
/**
197+
* Get a unique upload token for the java uploader. Must be logged in to do this
198+
* @param filename The name of the file to be uploaded
199+
*/
188200
function gethttpuploaduniqueidentifierAction()
189201
{
190202
$this->disableLayout();
191203
$this->disableView();
192204
$params = $this->_getAllParams();
193-
$this->Component->Httpupload->get_http_upload_unique_identifier($params);
205+
206+
if(!$this->logged)
207+
{
208+
throw new Zend_Exception('You have to be logged in to do that');
209+
}
210+
211+
if($this->userSession->JavaUpload->parent)
212+
{
213+
$folderId = $this->userSession->JavaUpload->parent;
214+
}
215+
else
216+
{
217+
$folderId = $this->userSession->Dao->getPrivatefolderId();
218+
}
219+
220+
$this->Component->Httpupload->setTmpDirectory($this->getTempDirectory());
221+
222+
$dir = $this->userSession->Dao->getUserId().'/'.$folderId;
223+
try
224+
{
225+
$token = $this->Component->Httpupload->generateToken($params, $dir);
226+
echo '[OK]'.$token['token'];
227+
}
228+
catch(Exception $e)
229+
{
230+
echo '[ERROR]'.$e->getMessage();
231+
throw $e;
232+
}
194233
} //end get_http_upload_unique_identifier
195234

196235

197-
/** process java upload*/
236+
/**
237+
* Process a java upload
238+
* @param uploadUniqueIdentifier The upload token (see gethttpuploaduniqueidentifierAction)
239+
* @param filename The name of the file being uploaded
240+
* @param length The length of the file being uploaded
241+
*/
198242
function processjavauploadAction()
199243
{
244+
$this->disableLayout();
245+
$this->disableView();
200246
$params = $this->_getAllParams();
247+
201248
if(!$this->logged)
202249
{
203-
echo "[ERROR] You must be logged in to upload";
250+
echo '[ERROR]You must be logged in to upload';
204251
throw new Zend_Exception('You have to be logged in to do that');
205252
}
206-
$this->disableLayout();
207-
$this->disableView();
253+
list($userId, $parentId, ) = explode('/', $params['uploadUniqueIdentifier']);
254+
if($userId != $this->userSession->Dao->getUserId())
255+
{
256+
echo '[ERROR]User id does not match upload token user id';
257+
throw new Zend_Exception('User id does not match upload token user id');
258+
}
259+
$expectedParentId = $this->userSession->JavaUpload->parent ?
260+
$this->userSession->JavaUpload->parent :
261+
$this->userSession->Dao->getPrivatefolderId();
262+
if($parentId != $expectedParentId)
263+
{
264+
echo '[ERROR]You are attempting to upload into the incorrect parent folder';
265+
throw new Zend_Exception('You are attempting to upload into the incorrect parent folder');
266+
}
208267

209-
$TMP_DIR = BASE_PATH.'/tmp/misc/';
210-
list ($filename, $path, $length) = $this->Component->Httpupload->process_http_upload($params);
268+
$this->Component->Httpupload->setTmpDirectory($this->getTempDirectory());
269+
$this->Component->Httpupload->setTestingMode(Zend_Registry::get('configGlobal')->environment == 'testing');
270+
$this->Component->Httpupload->setTokenParamName('uploadUniqueIdentifier');
271+
$data = $this->Component->Httpupload->process($params);
211272

212-
if(!empty($path) && file_exists($path) && $length > 0)
273+
if(!empty($data['path']) && file_exists($data['path']) && $data['size'] > 0)
213274
{
214275
if(isset($this->userSession->JavaUpload->parent))
215276
{
@@ -230,7 +291,7 @@ function processjavauploadAction()
230291

231292
try
232293
{
233-
$item = $this->Component->Upload->createUploadedItem($this->userSession->Dao, $filename, $path, $parent, $license);
294+
$item = $this->Component->Upload->createUploadedItem($this->userSession->Dao, $data['filename'], $data['path'], $parent, $license, $data['md5']);
234295
}
235296
catch(Exception $e)
236297
{

0 commit comments

Comments
 (0)