REBOL/IOS Download (Syncing) Control
For IOS Users Only REBOL Technologies
Contents:
1. Purpose
2. Fileset Priority Controls Download
3. Example of Creating a Non-Synchronized Fileset
4. How to Force a Download
5. An Uploader Program
6. A Downloader Program
1. Purpose
If the file has been published using the desktop, it will by default be
automatically synchronized to all clients that have access to that
fileset. In some cases, when dealing with large files, it may not be
desireable to automatically sync those large files. This document
describes a simple programming method of dealing with such files.
2. Fileset Priority Controls Download
As described in REBOL IOS Filesets, a fileset
can be given a priority to control its "importance" of synchronization.
More important files can be synchronized earlier in the process.
If the fileset priority is set to NONE (the word NONE), the fileset will
not be synchronized at all. In that case, the files must be requested
manually, as needed.
Examples of this method are shown below.
3. Example of Creating a Non-Synchronized Fileset
Here is a an example function call that will create a fileset that is
not synchronized:
fset: 'example
user-list: ["admin" "bob" "lisa"]
send-server new-app compose/deep [
(fset) [
priority: none ; no auto-sync
users: [(user-list)]
; (other tags)
]
[] ; no files
]
|
Now, if you upload a file, it will not be synchronized:
file: %projects/examples/test.txt
data: read/binary file
send-server add-file reduce [fset file compress data]
|
4. How to Force a Download
In order to synchronize the file that was uploaded earlier, you will
need to create a small script that requests the file to be downloaded.
The script can be as simple as:
REBOL [Title: "Download File" type: 'link-app]
fset: 'example
file: %projects/examples/test.txt
send-link 'download none reduce [fset file]
|
5. An Uploader Program
Here is an actual program we use to upload unsynchronized files to
specific users. We use this program as a way of providing updates for
large system files (such as complete servers and clients), but only when
users request them. The program also synchronizes a log of changes.
In this example, each user gets his own private fileset that keeps a
list of files (but the program could easily be modified to pubish files
to all users). To allow management access, the "admin" and other
managers are included in the fileset.
REBOL [
Title: "File Uploader"
Type: 'Link-app
Version: 1.1.3
Purpose: "Uploads unsync'd files to private fileset per user."
]
base: "releases" ; fileset "base name"
admin: ["admin" "carl"] ; shared with these managers
logfile: %upload-log.txt
users: sort extract load link-root/system/users.r 2
upload-user: func [name /local fset file data fl] [
; Get the file to upload:
files: request-file/title/file "Pick file to upload:" "Upload"
%/d/rebol/link/ranch/projects/express/license/
if none? files [exit]
; If user's private fileset does not exist, create it:
fset: to-word lowercase rejoin [base "!!" name]
get-link/sub-type 'app-tags func [a] [data: a] fset
if not data [
if not confirm "Create new fileset for user?" [exit]
send-server new-app compose/deep [(fset) [
priority: none ; no auto-sync
users: (reduce [unique join admin name])
][]]
]
; Create the filename and upload the file:
fl: flash "Uploading..."
foreach file files [
if error? try [data: read/binary file] [
alert "Error reading file"
exit
]
file: to-file rejoin [base "/" name "/" second split-path file]
if error? try [
send-server add-file reduce [fset file compress data]
][alert "Error uploading file." unview/only fl exit]
]
write/append logfile reform [name now files newline]
send-server add-file reduce [
'projects!releases!uploader!!7463633
%projects/releases/uploader/upload-log.txt
compress read logfile
]
unview/only fl
]
main: layout [
origin 0 space 2
text bold "Pick a User:"
ulst: text-list 150x300 data users [upload-user value]
]
view main
|
6. A Downloader Program
Here is the actual program that is used to download the files that were
uploaded with the program above. Note that the files are specific to
each user (the fileset "fset" is created with the user's filename).
REBOL [
Title: "File Downloader"
Type: 'Link-app
Version: 1.0.0
Purpose: "Downloads an unsync'd private file."
]
base: "releases" ; fileset prefix
fset: to-word rejoin [base "!!" user-prefs/name]
file-list: []
download: func [file] [
if exists? link-root/:file [
if not confirm reform ["Overwrite existing file?" file][exit]
]
send-link 'download none reduce [fset file]
]
main: layout [
origin 0 space 0
text bold "Select File to Download:"
lst: text-list 300x400 [download value]
]
on-file-list: func [event files] [
if files [
insert clear lst/data sort files
show lst/update
]
]
; Setup the event callback handlers:
insert-notify 'get none :on-file-list
insert-notify 'filesets-modified fset func [e f][
send-link 'get 'app-files fset ; fetch new list
]
insert-notify 'fileset-downloaded fset func [e files][
notify reform ["Download complete:" files]
]
; Ask for the list of files:
send-link 'get 'app-files fset
view main
|
| | REBOL/MakeDoc 2.0 | REBOL is a registered trademark of REBOL Technologies Copyright 2004 REBOL Technologies | 10-Sep-2004 |
|