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() -> String

    Return 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() -> String

    Return 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 nil if 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() -> Int

    Return 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 nil if the content has not been uploaded. The date and time stamp format is ISO 8601

    Declaration

    Swift

    public func getDate() -> String?

    Return Value

    The date the content was last modified in cloud storage, or nil if 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() -> SyncStatus

    Return 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 nil if 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 inputPath parameter is not nil, the outputPath will be set to nil. If the inputPath parameter is not nil and does not equal the current input path, the sync status will be reset to SyncStatus.notInSync.

    This method throws ClientError.state if getSyncStatus() returns SyncStatus.SYNC_PENDING.

    Throws

    • ClientError.file if inputPath does not identify an existing file
    • ClientError.argument if sync status is SYNC_PENDING

    Declaration

    Swift

    public func setInputPath(inputPath: String?) throws

    Parameters

    inputPath

    the 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 nil if 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 outputPath parameter is not nil, the input path will be set to nil. If the outputPath parameter is not nil and does not equal the current output path, the sync status will be reset to SyncStatus.notInSync

    This method throws ClientError.state if getSyncStatus() returns SyncStatus.SYNC_PENDING

    Throws

    throws:

    • ClientError.file if the outputPath cannot be written.
    • ClientError.state if called when sync status is SYNC_PENDING

    Declaration

    Swift

    public func setOutputPath(outputPath: String?) throws

    Parameters

    outputPath

    the 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.argument if the key or value is empty ClientError.state if the key or value is nil

    Declaration

    Swift

    public func setCustomMetadata(key: String, value: String) throws

    Parameters

    key

    The metadata key

    value

    The 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 setInputPath input path or the setOutputPath output path has been set. This method does not start any uploads or downloads if getSyncStatus is 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 SyncCallback on this StorageObject.

    If the input path cannot be read, or the output path cannot be written, an ClientError.file is thrown. Any I/O exceptions during the background sync are reported through the AbstractVirtualDevice.ErrorCallback error callback of the virtual device.

    Throws

    • ClientError.file if the the input path cannot be read, or the output path cannot be written
    • ClientError.state if both input path and output path are nil

    Declaration

    Swift

    public func sync() throws
  • Set a callback that is invoked when the content referred to by this StorageObject is synchronized.

    Declaration

    Swift

    public func setOnSync(callback: SyncCallback?)

    Parameters

    callback

    a callback to invoke when there is an error setting a value, if nil, the existing callback will be removed