Class: UploadItem

UploadItem Class

Namespace

ITHit.WebDAV.Client.Upload
Represents a file or folder being uploaded. Provides functions to discover item state, get info about upload progress as well as to pause, resume and cancel upload.
Name Type Description
sUrl string
oFsEntry ITHit.WebDAV.Client.Upload.FSEntry
oBinding ITHit.WebDAV.Client.Upload.Controls.HtmlControl
oSession ITHit.WebDAV.Client.Upload.UploaderSession
oGroupManager ITHit.WebDAV.Client.Upload.Groups.GroupManager
oSettings ITHit.WebDAV.Client.Upload.Settings

Members

CustomData :Object

CustomData
Stores custom data.

Methods

AddHeader(sName, sValue)

AddHeader
Adds HTTP header to upload. Note that depending on your web server and web browser, maximum allowed request header size or size of all headers in total may be limited.
Name Type Description
sName String Header name.
sValue String Header value.

AddListener(sEventName, fCallback, oContext)

AddListener
Add event handlers.
Name Type Description
sEventName string The event name to handle.
fCallback function The callback to call.
oContext object optional The context to callback is called with.

CancelAsync(iTryCount, iDelayAttempt, fCallback)

CancelAsync
Aborts upload.
Name Type Description
iTryCount number optional Number of times to try to delete the file if the file did not exist on the server before upload. Pass 0 to not try to delete the file. Default is: 5.
iDelayAttempt number optional Delay between attempts to delete in milliseconds. Default is: 500.
fCallback ITHit.WebDAV.Client.Upload.UploadItem~AsyncCallback optional The callback to call when upload is cancelled.

GetDeleteOnCancel() → {boolean}

GetDeleteOnCancel
Gets if the file is deleted when the upload is canceled.
Returns:
boolean True if file is deleted when upload is canceled. Otherwise - false. Default is true.

GetErrors() → {Array.<Error>|Array.<ITHit.WebDAV.Client.Exceptions.WebDavException>}

GetErrors
Gets all upload errors.
Returns:
Array.<Error> | Array.<ITHit.WebDAV.Client.Exceptions.WebDavException>

GetFile() → {File|null}

GetFile
Gets File object. Returns null in case of a folder.
Returns:
File | null

GetLastError() → {Error|ITHit.WebDAV.Client.Exceptions.WebDavException}

GetLastError
Gets last upload error.
Returns:
Error | ITHit.WebDAV.Client.Exceptions.WebDavException

GetName() → {string}

GetName
Gets file or folder name with extension.
Returns:
string File or folder name.

GetOverwrite() → {boolean}

GetOverwrite
Gets if the item will be overwritten if it exists on the server.
Returns:
boolean True if the file on the server will be overwritten. Otherwise - false. Default is false.

GetProgress() → {ITHit.WebDAV.Client.Upload.Progress}

GetProgress
Gets object that describes upload progress.
Returns:
ITHit.WebDAV.Client.Upload.Progress

GetRelativePath() → {string}

GetRelativePath
Gets relative path.
Returns:
string File or folder relative path.

GetState() → {ITHit.WebDAV.Client.Upload.State|string}

GetState
Gets current upload state.
Returns:
ITHit.WebDAV.Client.Upload.State | string

GetUrl() → {string}

GetUrl
Get target url.
Returns:
string File or folder target upload URL.

IsFolder() → {boolean}

IsFolder
Check if upload item represents a folder item.
Returns:
boolean True if item is a folder. Otherwise - false.

PauseAsync(fCallback)

PauseAsync
Pauses upload.
Name Type Description
fCallback ITHit.WebDAV.Client.Upload.UploadItem~AsyncCallback optional The callback to call when upload is paused.

RemoveListener(sEventName, fCallback, oContext)

RemoveListener
Remove event listener.
Name Type Description
sEventName string The event name to remove.
fCallback function The callback to call.
oContext object optional The context to callback is called with.

SetDeleteOnCancel(bDelete)

SetDeleteOnCancel
Sets if the file should be deleted if upload is canceled. By default, the file is deleted if the upload is canceled. To override this behavior, call this method passing false as a parameter. This function must be called on files only.
Name Type Description
bDelete boolean Specifies if the file should be deleted on cancel. Typically you will pass false if the file existed before upload. You will pass true to set the default behavior and delete the file when the upload is canceled.
Throws:
Thrown if this function is called on folder item.
Type
ITHit.Exceptions.ArgumentException

SetFailed(oError)

SetFailed
Sets failed state. Populates item's error with provided error instance.
Name Type Description
oError ITHit.WebDAV.Client.Exceptions.WebDavException The error instance that will be set as a failure description.
Throws:
- Thrown if argument is not derived from ITHit.WebDAV.Client.Exceptions.WebDavException.
Type
ITHit.Exceptions.ArgumentException
Example
var oUploader = new ITHit.WebDAV.Client.Upload.Uploader();
oUploader.Queue.OnUploadItemsCreated = function(oUploadItemsCreated) {
    var sErrorMessage = 'Added to queue in failed state';
     var oWebDavException = new ITHit.WebDAV.Client.Exceptions.WebDavException(sMessage);

     /** @typedef {ITHit.WebDAV.Client.Upload.UploadItem[]} aItemsToUpload */
    oUploadItemsCreated.Items.forEach(function(oItem) {
        oItem.SetFailed(oWebDavException);
    }

     oUploadItemsCreated.Upload(oUploadItemsCreated.Items);
});

SetOverwrite(Pass)

SetOverwrite
Sets if the item is overwritten if it exists on the server. If false is passed and the file exists on the server upload will fail and the UploadItem will be set in the error state. Default is false.
Name Type Description
Pass boolean true to force the file to be overwritten. Pass false to make upload fail if file exists.

StartAsync(fCallback)

StartAsync
Begins upload.
Name Type Description
fCallback ITHit.WebDAV.Client.Upload.UploadItem~AsyncCallback optional The callback to call when upload is paused.

Type Definitions

AsyncCallback()

AsyncCallback
Callback function to be called when action performed.

Events

OnBeforeUploadStarted

OnBeforeUploadStarted
Event fired before ITHit.WebDAV.Client.Upload.UploadItem started upload. You will validate item in this event and present user interface if user interaction is necessary. In this event you can check if each item exists on the server and specify if item should be overwritten or skipped. You can also validate file size, file extension, file upload path and file name. To continue upload the ITHit.WebDAV.Client.Upload.Events.BeforeUploadStarted#Upload function should be called. To skip upload the ITHit.WebDAV.Client.Upload.Events.BeforeUploadStarted#Skip function should be called.
Type:
Example
/** @typedef {ITHit.WebDAV.Client.Upload.UploadItem} oItem */
var oItem = oUploader.Queue.GetByUrl(sSomeUrl);
oItem.AddListener('OnBeforeUploadStarted', function(oBeforeUploadStarted) {
  WebDAVController.WebDavSession.OpenItemAsync(sHref,
      [],
      function(oAsyncResult) {
          if (oAsyncResult.IsSuccess) {
             oItem.SetSkip(true);
          }

          oBeforeUploadStarted.Done();
      });
});

OnError

OnError
Event reporting that upload error occurred.
Properties:
Name Type Description
Sender ITHit.WebDAV.Client.Upload.UploadItem Upload item instance.
Name string Event name.
Error. Error | ITHit.WebDAV.Client.Exceptions.WebDavException
Example
/** @typedef {ITHit.WebDAV.Client.Upload.UploadItem} oItem */
var oItem = oUploader.Queue.GetByUrl(sSomeUrl);
oItem.AddListener('OnError', function (oOnError) {
        console.log('Upload to:' + oOnError.Sender.GetUrl() +  ', failed with error:' + oOnError.Error.toString());
    });

OnProgressChanged

OnProgressChanged
Event reporting that upload item progress changed.
Properties:
Name Type Description
Sender ITHit.WebDAV.Client.Upload.UploadItem Upload item instance.
Name string Event name.
OldProgress ITHit.WebDAV.Client.Upload.Progress Previous progress.
NewProgress ITHit.WebDAV.Client.Upload.Progress Actual progress.
Example
/** @typedef {ITHit.WebDAV.Client.Upload.UploadItem} oItem */
var oItem = oUploader.Queue.GetByUrl(sSomeUrl);
oItem.AddListener('OnProgressChanged', function (oProgressChanged) {
        console.log('Upload to:' + oStateChanged.Sender.GetUrl() +  ', completed by:' + oProgressChanged.NewProgress.Completed + '%');
    });

OnStateChanged

OnStateChanged
Event reporting that upload item state changed.
Properties:
Name Type Description
Sender ITHit.WebDAV.Client.Upload.UploadItem Upload item instance.
Name string Event name.
OldState ITHit.WebDAV.Client.Upload.State Previous state.
NewState ITHit.WebDAV.Client.Upload.State Actual state.
Example
/** @typedef {ITHit.WebDAV.Client.Upload.UploadItem} oItem */
var oItem = oUploader.Queue.GetByUrl(sSomeUrl);
oItem.AddListener('OnStateChanged', function (oStateChanged) {
        console.log('Upload to:' + oStateChanged.Sender.GetUrl() +  ', changed state to :' + oStateChanged.NewState);
    });

OnUploadError

OnUploadError
Event fired when is possible to retry failed upload and waited until one of action called.
Type:
Example
/** @typedef {ITHit.WebDAV.Client.Upload.UploadItem} oItem */
var oItem = oUploader.Queue.GetByUrl(sSomeUrl);
AddListener('OnUploadError', function(oUploadError) {
  setTimeout(function() {
   oUploadError.Retry();
 }, 2000)
});