Still can't figure out upload download.

8 views
Skip to first unread message

rnrstar

unread,
Dec 17, 2010, 12:29:23 PM12/17/10
to RISE
I still haven't figure this out and your documentation seems to be
missing important info where various sentences abruptly end. In the
upload method, what is the $transactionID and what is the
$endOfTransaction arguments?

How is the data broken up? Is it broken up only on the upload or is it
broken up when it's put into the database thus creating multiple
records for a large file being uploaded? I would really appreciate
help on this as this is really the last item on my list for using RISE
for my projects.

Outside of RISE I have used the following code to upload and break
apart the file
----------start--------
function saveImage(){
$imageObj= new Images();
$txtFileName = $_FILES['Picture']['name'];
$tmpName = $_FILES['Picture']['tmp_name'];
$txtFileSize = $_FILES['Picture']['size'];
$txtFileType = $_FILES['Picture']['type'];

if($fileSize > 32000000) {

die("The file you are trying to upload is too large. Please select
a file that is less than 32 megabytes in size.");

} else {
# First create the image record.
$fieldarray = array('txtFileName'=>$txtFileName,
'txtFileSize'=>$txtFileSize,
'txtFileType'=>$txtFileType);
$intImageId = $imageObj->insertRecord($fieldarray);

# Now save the chunks of the image to the image parts table.
$intOrder=1;

$fp = fopen($tmpName, "r");
while (!feof($fp)) {
// Make the data mysql insert safe
$imagePart = addslashes(fread($fp, 65535));

$iPartObj=new ImageParts();
$fieldarray = array('intImageId'=>$intImageId,
'intOrder'=>$intOrder,
'blbContent'=>$imagePart);
$iPartObj->insertRecord($fieldarray);
$intOrder++;
}
return $intImageId;
}
}
} // end class
----------end clip--------------

Thanks in advance.

Joar Swenning

unread,
Dec 22, 2010, 9:27:47 AM12/22/10
to RISE
Hello,
The transactionID is generated (and returned) if you supply NULL, i.e.
start an
Upload/download transaction by passing NULL. endOfTransaction is set
when you retrieve
The last part on a download and should be set by you when passing the
last part of an
Upload. For download, the $startReadingAt and $maxBytesToRead
determines what subset
of the binary data to pick; grab no more than $maxBytesToRead starting
at byte
$startReadingAt. Actually, the chunking mechanism doesn't make much
sense when the
file's already uploaded as in your case with a PHP web app.

The samples below shows how to upload/download using RISE methods.
Note that $db is an
instance of a RISE interface object (in this case $db = new
copIDatabase($this->conn);).

The code below calls the method DownloadImageData (a RISE download
method) to fetch the
content of an image in 100kb blocks. When done, the $bytes variable
contains the image.

$ImageID = 123; // ID of image instance
$bytes = NULL;
$imd = (object)array('transactionId' => NULL, 'endOfTransaction' =>
FALSE);
do
{
$imd = $db->DownloadImageData($imd->transactionId,
strlen($bytes), 100000, $ImageID);
$bytes = $bytes.$imd->Data;
} while (!($imd->endOfTransaction===TRUE));

The code below call the method UploadImageData (a RISE upload method)
to write the content
of an image as a single block.

$db->UploadImageData(NULL, TRUE, $ImageID, $bytes);

I hope this helped and if not you might also want to make sure you
have installed tha latest version code generators.
Best regards,
Joar
Reply all
Reply to author
Forward
0 new messages