Class: UploadItem

UploadItem Class

Namespace

ITHit.WebDAV.Client.Upload

packagenew ITHit.WebDAV.Client.Upload.UploadItem(sUrl, oFsEntry, oBinding, oSession, oGroupManager)

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

Members

CustomDataObject

Stores custom data.
Gets or Sets OnUploadErrorCallback handler.
Gets or Sets OnUploadStartedCallback handler.

Methods

AddListener(sEventName, fCallback, oContext)

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)

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 cancelled.

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

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

GetFile(){File|null}

Gets File object. Returns null in case of a folder.
Returns:
File | null
Gets last upload error.
Returns:
Error | ITHit.WebDAV.Client.Exceptions.WebDavException

GetName(){string}

Gets file or folder name with extension.
Returns:
string
Gets object that describes upload progress.
Returns:
ITHit.WebDAV.Client.Upload.Progress

GetRelativePath(){string}

Gets relative path.
Returns:
string

GetRewrite(){boolean}

Gets rewrite behavior.
Returns:
boolean
Gets current upload state.
Returns:
ITHit.WebDAV.Client.Upload.State | string

GetUrl(){string}

Get target url.
Returns:
string

PauseAsync(fCallback)

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

RemoveListener(sEventName, fCallback, oContext)

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.

SetRewrite(bRewrite)

Sets rewrite behavior. Can't be set true if item represents folder.
Name Type Default Description
bRewrite boolean false optional

SetSkip()

Sets skip state. Skipped items will not be added to queue or automatically uploaded if they already in queue.

StartAsync(fCallback)

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

Type Definitions

AsyncCallback()

Callback function to be called when action performed.

OnUploadErrorCallback(oEvent)

Callback function to be called when is possible to retry failed upload and waited until one of action called.
Name Type Description
oEvent ITHit.WebDAV.Client.Upload.Events.OnUploadError Event Object
Example
/** @typedef {ITHit.WebDAV.Client.Upload.UploadItem} oItem */
var oItem = oUploader.Queue.GetByUrl(sSomeUrl);
oItem.OnUploadErrorCallback = function (oOnUploadError) {
  setTimeout(function() {
   oUploadError.Retry();
 }, 2000)
};

OnUploadStartedCallback(oEvent)

Callback function to be called before ITHit.WebDAV.Client.Upload.UploadItem begins upload and waited until one of action called.
Name Type Description
oEvent ITHit.WebDAV.Client.Upload.Events.UploadStarted Event Object
Example
/** @typedef {ITHit.WebDAV.Client.Upload.UploadItem} oItem */
var oItem = oUploader.Queue.GetByUrl(sSomeUrl);
oItem.OnUploadStartedCallback = function (oOnBeforeUploadStart) {
  WebDAVController.WebDavSession.OpenItemAsync(sHref,
      [],
      function(oAsyncResult) {
          if (oAsyncResult.IsSuccess) {
             oItem.SetSkip(true);
          }

          oBeforeUploadStart.Done();
      });
};

Events

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

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

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);
    });