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

CustomDataObject

Stores custom data.

Methods

AddHeader(sName, sValue)

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)

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

GetDeleteOnCancel(){boolean}

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

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 File or folder name.

GetOverwrite(){boolean}

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.
Gets object that describes upload progress.
Returns:
ITHit.WebDAV.Client.Upload.Progress

GetRelativePath(){string}

Gets relative path.
Returns:
string File or folder relative path.
Gets current upload state.
Returns:
ITHit.WebDAV.Client.Upload.State | string

GetUrl(){string}

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

PauseAsync(fCallback)

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)

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)

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)

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)

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)

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

Type Definitions

AsyncCallback()

Callback function to be called when action performed.

Events

OnBeforeUploadStarted

Event fired before ITHit.WebDAV.Client.Upload.UploadItem started upload.
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

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

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