StorageObject
public class StorageObject : ExternalObject
StorageObject provides information about content in cloud storage.
// Upload example
var lenna:StorageObject =
directlyConnectedDevice.createStorageObject(name:"lenna.jpg",
contentType: "image/jpeg")
lenna.setInputPath(inputPath:"images/lenna.jpg")
// onSync is called when the content referenced by the storageObject
// is in sync with the storage cloud, or the sync has failed.
lenna.setOnSync(callback: { event in
let storageObject:StorageObject = event.getSource()
if storageObject.getSyncStatus() == SyncStatus.inSync {
// image was uploaded and can be deleted
} else if storageObject.getSyncStatus() == SyncStatus.syncFailed {
// image was not uploaded, take action!
}
})
virtualDevice.set(attributeName:"image", attributeValue:lenna)
// Download example
// onChange is called when the attribute value changes.
virtualDevice.setOnChange(attributeName:"image", callback: { event in
var namedValue:NamedValue = event.getNamedValue()
var storageObject:StorageObject = namedValue.getValue() as StorageObject
if storageObject.getContentLength() < availableDiskSpace {
// syncTo will kick off the async download of the content
storageObject.setOnSync(callback: { event in
let storageObject:StorageObject = event.getSource()
if storageObject.getSyncStatus() == SyncStatus.inSync {
// image was downloaded and can now be used
} else if storageObject.getSyncStatus() == SyncStatus.syncFailed {
// image was not downloaded, take action!
}
}
storageObject.setOutputPath(outputPath:"downloads" +
storageObject.getName())
storageObject.sync()
}
})
}
-
Undocumented
Declaration
Swift
public static let OCTET_STREAM: String -
Get the the name of this object in the storage cloud.
Declaration
Swift
public func getName() -> StringReturn Value
the name of this object in the storage cloud
-
Get the mime-type of the content. See IANA Media Types
Declaration
Swift
public func getContentType() -> StringReturn Value
The mime-type of the content
-
Get the compression scheme of the content.
Declaration
Swift
public func getEncoding() -> String?Return Value
the compression scheme of the content, or
nilif the content is not compressed -
Get the length of the content in bytes. This is the number of bytes required to upload or download the content.
Declaration
Swift
public func getLength() -> IntReturn Value
The length of the content, or -1 if unknown
-
Get the date and time the content was created or last modified in cloud storage. This may be
nilif the content has not been uploaded. The date and time stamp format isISO 8601Declaration
Swift
public func getDate() -> String?Return Value
The date the content was last modified in cloud storage, or
nilif the content has not been uploaded. -
Get the status of whether or not the content is in sync with the storage cloud.
Declaration
Swift
public func getSyncStatus() -> SyncStatusReturn Value
the status of whether or not the content is in sync with the storage cloud.
-
Get the input path.
Declaration
Swift
public func getInputPath() -> String?Return Value
the input path, or
nilif not set -
Set the input path for uploading content to the storage cloud. The implementation allows for either the input path to be set, or the output path to be set, but not both.
If the
inputPathparameter is notnil, theoutputPathwill be set tonil. If theinputPathparameter is notniland does not equal the current input path, the sync status will be reset toSyncStatus.notInSync.This method throws
ClientError.stateifgetSyncStatus()returnsSyncStatus.SYNC_PENDING.Throws
ClientError.fileifinputPathdoes not identify an existing fileClientError.argumentif sync status isSYNC_PENDING
Declaration
Swift
public func setInputPath(inputPath: String?) throwsParameters
inputPaththe path from which to read the content for upload
-
Get the output path.
Declaration
Swift
public func getOutputPath() -> String?Return Value
the output path, or
nilif not set -
Set the output path for downloading content from the storage cloud. The implementation allows for either the output path to be set, or the input path to be set, but not both.
If the
outputPathparameter is notnil, the input path will be set tonil. If theoutputPathparameter is notniland does not equal the current output path, the sync status will be reset toSyncStatus.notInSyncThis method throws
ClientError.stateifgetSyncStatus()returnsSyncStatus.SYNC_PENDINGThrows
throws:
ClientError.fileif theoutputPathcannot be written.ClientError.stateif called when sync status isSYNC_PENDING
Declaration
Swift
public func setOutputPath(outputPath: String?) throwsParameters
outputPaththe path to which the content will be downloaded If the path does not exist, it will be created.
-
Sets the metadata for the StorageObject. All metdata will be added to Storage Cloud Service as custom metadata with the X-Object-Meta-KeyName header.
Throws
ClientError.argumentif the key or value is emptyClientError.stateif the key or value isnilDeclaration
Swift
public func setCustomMetadata(key: String, value: String) throwsParameters
keyThe metadata key
valueThe metadata value
-
This method return unmodifiable copy of metadata.
Declaration
Swift
public func getCustomMetadata() -> [String : String]Return Value
Map of metadata. Map may be empty.
-
Notify the library to sync content with the storage cloud. The direction of the sync, upload or download, depends on whether the
setInputPathinput path or thesetOutputPathoutput path has been set. This method does not start any uploads or downloads ifgetSyncStatusis other than `SyncStatus.notInSync.This is a non-blocking call. The sync is performed on a separate thread. The status of the sync can be monitored by setting a
SyncCallbackon thisStorageObject.If the input path cannot be read, or the output path cannot be written, an
ClientError.fileis thrown. Any I/O exceptions during the background sync are reported through theAbstractVirtualDevice.ErrorCallbackerror callback of the virtual device.Throws
ClientError.fileif the the input path cannot be read, or the output path cannot be writtenClientError.stateif both input path and output path arenil
Declaration
Swift
public func sync() throws -
Set a callback that is invoked when the content referred to by this
StorageObjectis synchronized.Declaration
Swift
public func setOnSync(callback: SyncCallback?)Parameters
callbacka callback to invoke when there is an error setting a value, if
nil, the existing callback will be removed
StorageObject Class Reference