Category: Question and Answers
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Upload files to local shared folder (SELF HOST)

Issue

I am creating a pocket clinic CRM and need to upload image reports for treatments into a local folder with private access. The S3 filepicker tutorial provided public access and isn't suitable. I am looking for a tutorial on how to create a local photo gallery with CRUD capabilities using a file manager widget linked to filepicker.

Resolution

Unfortunately, it appears that the user is requesting a solution that is not recommended from a security standpoint. It is not best practice to store sensitive data such as medical images in a local folder that is hosted on the same server as the app. A better solution would be to store the images in a private S3 bucket, where access can be strictly controlled through IAM roles and policies.

To use a private S3 bucket, the user can follow AWS documentation to create the bucket and set policies to control access. They can then use the AWS SDK to upload and manage the images within the bucket.

As for integrating with Appsmith, they can use the Filepicker widget to select the images and initiate the upload process to the S3 bucket. They can then use Appsmith's API features to manage and display the images within their app.

Here is an example code snippet for uploading an image to a private S3 bucket using the AWS SDK in Node.js:

const AWS = require('aws-sdk');
const fs = require('fs');

// Set up AWS credentials and S3 object
AWS.config.update({
accessKeyId: 'your-access-key-id',
secretAccessKey: 'your-secret-access-key'
});

const s3 = new AWS.S3({
endpoint: 'your-s3-bucket-endpoint'
});

// Read image file from local directory
const fileContent = fs.readFileSync('path-to-image-file');

// Set S3 upload parameters
const params = {
Bucket: 'your-bucket-name',
Key: 'unique-image-key',
Body: fileContent
};

// Upload image to S3 bucket
s3.upload(params, (err, data) => {
if (err) {
console.error(err);
} else {
console.log(`File uploaded successfully. ${data.Location}`);
}
});