Renovation
Search…
.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

1
renovation.storage
2
.uploadFile({
3
fileBuffer: buffer,
4
fileName: "sample.txt"
5
})
6
.subscribe(
7
status => {
8
switch (status.status) {
9
case "uploading":
10
console.log(`Uploaded: ${status.progress}`);
11
break;
12
case "completed":
13
console.log("Upload completed");
14
break;
15
default:
16
}
17
},
18
err => console.error(err),
19
() => console.log("BehaviorSubject Done");
20
);
Copied!

.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
1
const createFolder = await renovation.storage.checkFolderExists(
2
"Home/" + existingFolder
3
);
4
console.log("Folder exists: " + createFolder.data);
Copied!
Classic Promise
1
renovation.storage
2
.checkFolderExists("Home/" + existingFolder)
3
.then(result => console.log("Folder exists: " + result.data));
Copied!

.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
1
const createFolder = await renovation.storage.createFolder("New Folder");
2
console.log(createFolder.success);
Copied!
Classis Promise
1
renovation.storage
2
.createFolder("New Folder")
3
.then(result => console.log(result.success));
Copied!

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

1
const fileUrl = renovation.storage.getUrl("/files/file-1.jpg");
2
console.log(fileUrl); // https://abc.com/files/file-1.jpg
Copied!
Last modified 1yr ago