.storage

Controller containing properties and methods dealing with uploading of files.

.uploadFile() ☆

To upload file to the backend using Socket IO.

In case the socketio fails during uploading, a fallback upload is done through HTTP which doesn't have progress update.

Input

UploadFileParams

property

type

required

description

file

File

no

File to upload to the backend

fileName

string

no

File name

isPrivate

boolean

no

Whenever the file is private or not

filePath

string

no

The path to the target file.

fileBuffer

Buffer

no

If the file is of kind Buffer, define this property

folder

string

no

Specify the folder to be uploaded to.

doctype

string

no

If the file is to be linked with a document, specify the doctype.

docname

string

no

If the file is to be linked with a document, specify the docname.

docfield

string

no

If the file is to be linked with a document, specify the field to attach the file to.

doc

RenovationDocument

no

Optionally supply the document to which the file is attached. Assigns the field's value to the file_url of the file uploaded.

Output

BehaviorSubject<UploadFileStatus>

Example

renovation.storage
.uploadFile({
fileBuffer: buffer,
fileName: "sample.txt"
})
.subscribe(
status => {
switch (status.status) {
case "uploading":
console.log(`Uploaded: ${status.progress}`);
break;
case "completed":
console.log("Upload completed");
break;
default:
}
},
err => console.error(err),
() => console.log("BehaviorSubject Done");
);

.checkFolderExists()

To check if given folder name exits on the backend

Input

property

type

required

description

folderDir

string

yes

Folder path to be checked

Output

boolean

Example

async-await

const createFolder = await renovation.storage.checkFolderExists(
"Home/" + existingFolder
);
console.log("Folder exists: " + createFolder.data);

Classic Promise

renovation.storage
.checkFolderExists("Home/" + existingFolder)
.then(result => console.log("Folder exists: " + result.data));

.createFolder()

Creates a folder in the backend.

Input

property

type

required

description

folderName

String

yes

Folder name

parentFolder

String

no

Parent folder to create the folder ,default = "Home"

Output

any

Example

async-await

const createFolder = await renovation.storage.createFolder("New Folder");
console.log(createFolder.success);

Classis Promise

renovation.storage
.createFolder("New Folder")
.then(result => console.log(result.success));

Possible Errors

Wring input

HTTP code: 412

type: DataFormatError

cause: Folder name forward with slash

suggestion: remove the slash from folder name

.getUrl()

Appends proper Nginx access urls.

Input

property

type

required

description

ref

string

yes

Folder path to be checked

Output*

string

If the URL contains http or is null, the result is returned as is. Otherwise the host URL will be appended to the file_url.

Example

const fileUrl = renovation.storage.getUrl("/files/file-1.jpg");
console.log(fileUrl); // https://abc.com/files/file-1.jpg