frapi / frapi

FRAPI is an API Open Source framework, run it within your hosting environment parallel to your web app, mobile service or legacy system.

Home Page:http://getfrapi.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multipart uploads from iOS hanging

dennisaschmidt opened this issue · comments

I have successfully sent multipart body file uploads to a post transaction in Frapi (code below) from an android client, see an example here:
http://posttestserver.com/data/2013/03/30/08.46.24641073794

I am now developing an iOS version of our application, but it hangs on the Frapi response. Here are two examples of uploading the same file that timeout from the iOS client with Frapi:
http://posttestserver.com/data/2013/03/30/08.30.511941716186
http://posttestserver.com/data/2013/03/30/08.36.411246160985

The client I am using is provided by AFNetworking (whereas the client I used on Android was Apache HttpClient with a MultipartEntity).

data['UserID'] = $this->getParam('UserID', self::TYPE_OUTPUT); $this->data['TechCode'] = $this->getParam('TechCode', self::TYPE_OUTPUT); $this->data['InvNmbr'] = $this->getParam('InvNmbr', self::TYPE_OUTPUT); $this->data['SchdItmID'] = $this->getParam('SchdItmID', self::TYPE_OUTPUT); $this->data['Description'] = $this->getParam('Description', self::TYPE_OUTPUT); $this->data['UIS'] = $this->getParam('UIS', self::TYPE_OUTPUT); $this->data['FileSize'] = $this->getParam('FileSize', self::TYPE_OUTPUT); $this->data['FileType'] = $this->getParam('FileType', self::TYPE_OUTPUT); $this->data['FileName'] = $this->getParam('FileName', self::TYPE_OUTPUT); $this->data['File'] = $this->getParam('File', self::TYPE_FILE); // changed from TYPE_OUTPUT $this->data['PictureSnappedDate'] = $this->getParam('PictureSnappedDate', self::TYPE_OUTPUT); return $this->data; } /** - Default Call Method - - This method is called when no specific request handler has been found - - @return array */ public function executeAction() { $valid = $this->hasRequiredParameters($this->requiredParams); if ($valid instanceof Frapi_Error) { throw $valid; } return $this->toArray(); } /** - Get Request Handler - - This method is called when a request is a GET - - @return array */ public function executeGet() { $valid = $this->hasRequiredParameters($this->requiredParams); if ($valid instanceof Frapi_Error) { throw $valid; } return $this->toArray(); } /** - Post Request Handler - - This method is called when a request is a POST - - @return array */ public function executePost() { $valid = $this->hasRequiredParameters($this->requiredParams); if ($valid instanceof Frapi_Error) { throw $valid; } // Connect to our database $db = Frapi_Database::getInstance(); $imageData = ""; $fileparam = $this->getParam('File', self::TYPE_FILE); $filename = $fileparam["tmp_name"]; if (file_exists($filename) && is_readable ($filename)) { $fh = fopen($filename, "r"); while (!feof($fh)) { $hex = bin2hex(fread ($fh , 4 )); $imageData = $imageData . $hex; } fclose($fh); } $sql = "INSERT INTO `rDrive_Uploads` (`UserID`, `TechCode`, `InvNmbr`, `SchdItmID`, `Description`, `UisID`, `FileSize`, `FileType`, `FileName`, `File`, `PictureSnappedDate`) VALUES('" . $this->getParam('UserID', self::TYPE_OUTPUT) ."', '" . $this->getParam('TechCode', self::TYPE_OUTPUT) ."','" . $this->getParam('InvNmbr', self::TYPE_OUTPUT) ."','" . $this->getParam('SchdItmID', self::TYPE_OUTPUT) ."','" . $this->getParam('Description', self::TYPE_OUTPUT) ."','" . $this->getParam('UIS', self::TYPE_OUTPUT) ."','" . $this->getParam('FileSize', self::TYPE_OUTPUT) ."','" . $this->getParam('FileType', self::TYPE_OUTPUT) ."','" . $this->getParam('FileName', self::TYPE_OUTPUT) ."',x'" . $imageData ."','" . $this->getParam('PictureSnappedDate', self::TYPE_OUTPUT) ."')"; ``` $stmt = $db->prepare($sql); $stmt->execute(); $Upload_result = str_pad($db->lastInsertId(), 10, "0", STR_PAD_LEFT) ; // Create an array of data to use in our template file $this->data[] = array('Upload' => array('FileID' => $Upload_result)); $db = null; return $this->toArray(); } /** * Put Request Handler * * This method is called when a request is a PUT * * @return array */ public function executePut() { $valid = $this->hasRequiredParameters($this->requiredParams); if ($valid instanceof Frapi_Error) { throw $valid; } return $this->toArray(); } /** * Delete Request Handler * * This method is called when a request is a DELETE * * @return array */ public function executeDelete() { $valid = $this->hasRequiredParameters($this->requiredParams); if ($valid instanceof Frapi_Error) { throw $valid; } return $this->toArray(); } /** * Head Request Handler * * This method is called when a request is a HEAD * * @return array */ public function executeHead() { $valid = $this->hasRequiredParameters($this->requiredParams); if ($valid instanceof Frapi_Error) { throw $valid; } return $this->toArray(); } ``` }

Appeared to be a server issue, I removed the Accept headers and it worked.