IPWorks Cloud 2020 Node.js Edition

Questions / Feedback?

UploadFile Method

Uploads a new file resource.

Syntax

box.uploadFile(fileName, parentId, [callback])

Callback

The 'callback' parameter specifies a function which will be called when the operation completes (or an error is encountered). If the 'callback' parameter is not specified, then the method will block and will not return until the operation completes (or an error is encountered).

The callback for this method is defined as:

function(err, data){ }

'err' is the error that occurred. If there was no error, then 'err' is 'null'.

'data' is the value returned by the method.

'err' has 2 properties which hold detailed information:

err.code
err.message

Remarks

This method uploads a new file resource named FileName to the folder specified by ParentId. The Id of the newly-created file resource is returned.

FileName must be no longer than 255 characters; may not contain /, \, non-printable ASCII characters, or trailing whitespace; and cannot be one of the special names . or ...

ParentId can be empty, in which case the file is uploaded to the root folder.

The ClientCreatedTime and ClientModifiedTime configuration settings may be set before calling this method to submit those timestamps along with the file data.

If LocalFile is set the file will be uploaded from the specified path. If LocalFile is not set the data in ResourceData will be used.

To encrypt the file before uploading it, set EncryptionAlgorithm and EncryptionPassword.

Upload Notes

Box offers two ways to upload a file. For smaller files a simple upload option is provided to upload data in one request. This is the default option. For larger files (must be larger than 20 MB), uploads can be fragmented into multiple pieces, allowing resuming of uploads that may be interrupted.

Simple

By default the class uses the simple upload mechanism. When doing a simple upload, the HashSimpleUploads setting is applicable.

box.LocalFile = "../MyFile.zip";
box.UploadFile("MyFile.zip", "");

Resumable

To enable resumable uploads set UseResumableUpload to true. This is recommended for large files (must be larger than 20 MB). The class will automatically fragment the specified file into smaller pieces and upload each individually.

When UseResumableUpload is set to true and UploadFile is called, a resumable upload session is started by the class. ResumeURL is populated with a URL identifying the session (this value may be needed for additional operations if the upload does not complete normally).

During a resumable upload, the FragmentComplete event fires after each fragment is uploaded to indicate overall progress. The class also updates StartByte as necessary to indicate the current offset in the file.

If the upload is interrupted for any reason, resuming it is easy. First, verify that ResumeURL is populated (if the same instance of the class is used, it should already be populated, and no special action should be needed). Call PollUploadStatus to populate the correct values for StartByte and UploadFragmentSize. Then call UploadFile again to resume the upload at the specified StartByte offset.

Note that if the upload is not resumed after some time the upload session will expire. PollUploadStatus may be used to check the status of a resumable upload, including when it will expire (which is stored in the UploadExpDate configuration setting). An interrupted upload can be aborted explicitly using the AbortUpload method.

box.LocalFile = "../MyFile.zip";
box.UploadFile("MyFile.zip", "");

//The transfer is interrupted and UploadFile() above fails. Later, resume the download.
//Using the same instance StartByte and ResumeURL are already populated from the previous
//upload attempt.
box.UploadFile("MyFile.zip", "");

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks Cloud 2020 Node.js Edition - Version 20.0 [Build 8265]