Upload a File
You can upload a file from your local system to an existing folder in the File Store, by referring to the folder’s unique ID. You can upload an image, text document, CSV, or any type of file you need. The maximum size of a file that you can upload is 100 MB. A unique File ID is created for the file after it is uploaded.
Create a JSON Configuration
You must initially create a JSON configuration object for the file to be uploaded, as shown below. This JSON object creates a ReadStream() for the file. You can include the file name in it optionally.
copy//Create a JSON object with the file and its name, using the keys 'name' and 'code' let config = { code:fs.createReadStream('empdata.csv'), name: 'testFile.txt' };
Upload the File
You must now upload the file by passing the JSON object to the uploadFile() method, as shown below.
You can either use the folder reference or the folder meta created earlier, to refer the folder where the file needs to be uploaded in. You must pass the unique Folder ID of the folder. The promise returned here will be resolved to a JSON object with the uploaded file information.
copy//Upload the file by passing the JSON config to the method, which in turn returns a promise let filestore = app.filestore(); let folder = filestore.folder(1510000000109545); //Provide the Folder ID let uploadPromise = folder.uploadFile(config); //Pass the JSON object created for the file uploadPromise.then((fileObject) => { console.log(fileObject); });
A sample response that you will receive for each version is shown below:
Node JScopy
{
id: "2136000000020122",
file_location: null,
file_name: "empdata.csv",
file_size: "84881",
created_by: {
zuid: "66466723",
is_confirmed: false,
email_id: "emma@zylker.com",
first_name: "Amelia",
last_name: "Burrows",
user_type: "Admin",
user_id: "2136000000006003"
},
created_time: "Aug 17, 2021 09:33 PM",
modified_by: {
zuid: "66466723",
is_confirmed: false,
email_id: "emma@zylker.com",
first_name: "Amelia",
last_name: "Burrows",
user_type: "Admin",
user_id: "2136000000006003"
},
modified_time: "Aug 17, 2021 09:33 PM",
project_details: { project_name: "ShipmentTracking", id: "2136000000007733" },
folder_details: "2136000000008551"
}
{
id: 2136000000020117,
file_location: null,
file_name: "empdata.csv",
file_size: 84881,
created_by: {
zuid: 66466723,
is_confirmed: false,
email_id: "emma@zylker.com",
first_name: "Amelia",
last_name: "Burrows",
user_type: "Admin",
user_id: 2136000000006003
},
created_time: "Aug 17, 2021 09:33 PM",
modified_by: {
zuid: 66466723,
is_confirmed: false,
email_id: "emma@zylker.com",
first_name: "Amelia",
last_name: "Burrows",
user_type: "Admin",
user_id: 2136000000006003
},
modified_time: "Aug 17, 2021 09:33 PM",
project_details: { project_name: "ShipmentTracking", id: 2136000000007733 },
folder_details: 2136000000008551
}
Last Updated 2023-09-03 01:06:41 +0530 +0530
Yes
No
Send your feedback to us