The plUpload handler class is a Web Connection server backend for the plUpload component. plUpload allows uploads of multiple files and can support uploads of files larger than the 16 megs that Visual FoxPro's string limit imposes on Web Connection.
plUpload provides a simple facade for plUpload on the server side that can be implemented with very little code and almost no knowledge of the protocol that plUpload uses internally. The handler class provides a simple, self-contained implementation that uses the Web Connection intrinsic objects to handle plUpload requests and routes to various 'events' like OnUploadStarted(), OnUploadChunk() and OnUploadComplete() that notifies your Web Connection application.
Typical implementations that upload to a file on the server only need to implement the OnUploadComplete event or the cOnUploadCompleteFunction pointer to provide an implementation for what happens when the upload completes.
For more information please see:
Class Members
Member | Description | |
---|---|---|
OnUploadChunk |
This method is called when when a file chunk is uploaded. o.OnUploadChunk(lcData, lnChunk, lnChunks, lcFilename, loUpload) |
|
OnUploadComplete |
This method is called when an upload of an individulal flie is complete. The filename is passed and you can then decide what to do with the file. o.OnUploadComplete(lcFileName, loUpload) |
|
OnUploadStarted |
This method is called when an individual file upload is started. o.OnUploadStarted(lcFilename, loUpload) |
|
ProcessRequest |
This method starts processing the current plUpload file chunk requests. o.ProcessRequest() |
|
WriteCompletionResponse |
Use this method in OnUploadComplete() to send a message back to the client. Typically this will be the URL of the file uploaded so it can be viewed or shows as part of the UI. o.WriteCompletionResponse(lcData) |
|
WriteErrorResponse |
This method is used to return an error response while processing a chunk of the uploaded file. Any error results should use this method to communicate error messages. o.WriteErrorResponse(lcMessage, lnStatusCode) |
|
WriteSuccessResponse |
Used internally to write a chunk success response if a chunk request completed properly. o.WriteSuccessResponse(lcMessage) |
|
cUploadPath |
The path where files are stored when a file is uploaded from the client. | |
nMaxUploadSize |
The maximum upload size in bytes for files. |
Example
*** Process Method
FUNCTION plUploadSample
loUpload = CREATEOBJECT("plUploadHandler")
*** Upload to temp folder
loUpload.cUploadPath = ADDBS(THIS.oConfig.cHtmlPagePath) + "temp"
*** Hook OnUploadComplete event to local method
BINDEVENT(loUpload,"OnUploadComplete",THIS,"OnUploadComplete",1)
*** Constrain the extensions allowed on the server
loUpload.cAllowedExtensions = "jpg,jpeg,png,gif"
*** Process the file or chunk
loUpload.ProcessRequest()
ENDFUNC
*** Event handler also in Process class
*** Only requirement is to call loUpload.WriteCompletionResponse()
*** to write output string that client can receive.
FUNCTION OnUploadComplete(lcFilename, loUpload)
LOCAL lcUrl, lcFile
lcUrl = this.ResolveUrl("~/temp/" + lcFileName)
*** Resize the image
lcFile = ADDBS(loUpload.cUploadPath) + lcFileName
ResizeImage(lcFile,lcFile,640,480)
*** Delete expired files - only for 10 minutes
DeleteFiles(ADDBS(JUSTPATH(lcFile)) + "*.*",600)
*** Write out the response for the client (if any)
*** In this case the URL to the uploaded image
loUpload.WriteCompletionResponse(lcUrl)
ENDFUNC
<!DOCTYPE html>
<html>
<head>
<title>plUploadSample</title>
<link href="../westwind.css" rel="stylesheet" type="text/css" />
<link href="../scripts/plupload/jquery.plupload.queue/css/jquery.plupload.queue.css"
rel="stylesheet"
type="text/css" />
<script src="../scripts/jquery.js" type="text/javascript"></script>
<script src="../scripts/ww.jquery.js" type="text/javascript"></script>
<script src="../scripts/plupload/plupload.full.js"></script>
<script src="../scripts/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
</head>
<body>
<h1>plUpload File Upload Sample</h1>
<div class="containercontent">
<!-- Container to preview images - Optional to sample-->
<div id="ImageContainer">
</div>
<!-- Upload control renders into here -->
<div id="Uploader">
</div>
</div>
<script> // on next page </script>
</body>
</html>
<script>
$(document).ready(function () {
$("#Uploader").pluploadQueue({
runtimes: 'html5,silverlight,flash,html4',
url: 'plUpload.wwd',
max_file_size: '2mb',
chunk_size: '64kb',
unique_names: false,
// Resize images on clientside if we can
resize: { width: 800, height: 600, quality: 90 },
// Specify what files to browse for
filters: [{ title: "Image files", extensions: "jpg,jpeg,gif,png" }],
flash_swf_url: '../scripts/plupload/plupload.flash.swf',
silverlight_xap_url: '../scripts/plupload/plupload.silverlight.xap',
multiple_queues: true
});
// get uploader instance
var uploader = $("#Uploader").pluploadQueue();
// bind uploaded event and display the image
// response.response returns the last response from server
// which is the URL to the image that was sent by OnUploadCompleted
uploader.bind("FileUploaded", function (upload, file, response) {
// remove the file from the list
upload.removeFile(file);
// Response.response returns server output from onUploadCompleted
// our code returns the url to the image so we can display it
var imageUrl = response.response;
$("<img>").attr({ src: imageUrl })
.appendTo($("#ImageContainer"));
});
// Error handler displays client side errors and transfer errors
// when you click on the error icons
uploader.bind("Error", function (upload, error) {
showStatus(error.message, 3000, true);
});
});
</script>
Requirements
Assembly: pluploadhandler.prgSee also:
How plUploadHandler works© West Wind Technologies, 1996-2024 • Updated: 12/26/15
Comment or report problem with topic