Controller containing properties and methods dealing with uploading of files.
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.
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 |
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. |
BehaviorSubject<UploadFileStatus>
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"););
To check if given folder name exits on the backend
property | type | required | description |
folderDir | string | yes | Folder path to be checked |
boolean
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));
Creates a folder in the backend.
property | type | required | description |
folderName | String | yes | Folder name |
parentFolder | String | no | Parent folder to create the folder ,default = "Home" |
any
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));
HTTP code:
412
type:
DataFormatError
cause: Folder name forward with slash
suggestion: remove the slash from folder name
Appends proper Nginx access urls.
property | type | required | description |
ref | string | yes | Folder path to be checked |
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.
const fileUrl = renovation.storage.getUrl("/files/file-1.jpg");console.log(fileUrl); // https://abc.com/files/file-1.jpg