This code represents a medium to upload your media to a server where this app will be hosted and Serve them.
Currently Supported medias collectively are image, Video, Audio, others
There are a limited number of extensions that are configured for this code to work perfectly on, as i didn't do proper research to all the file extensions supported on a media
URL for serving:
<protocol>://<hostAddress>:<port>/srv/<key>
Example:http://localhost:3000/srv/hJ9Hdb14
There is also a Uploading test site provided which is accessible through
URL:
<protocol>://<hostAddress>:<port>/test
Example:http://localhost:3000/test
This Variables are to be placed into .env
and config.js
files on the root directory of the app after creation of the files
Var Name | Var Definition | Var In | Required |
---|---|---|---|
PORT | Port Number on which the server will be running on | .env | YES |
MONGODB_URI | URI String to Connecting to MongoDB for URL, file registration | .env | YES |
hostAddress | This Variable will be responsible for making the url that will be serving the file to a end user | config.js | YES |
Template:
PORT= # The port that the app will hosted on
MONGODB_URI= # The URI string to the mongoDB Database
Template:
require("dotenv/config");
module.exports = {
hostAddress: "<protocol>://<Your Host Address>:" + process.env.PORT + "/",
};
- Clone the Code to your desired Location.
- Install the dependencies with package manager of your liking.
- Installing Using Yarn
- Run the command 'yarn' at the root of the repository
- After Installation, configure the '.env' file and 'config.js' files according to the Environment Set up guide
- Run the command 'yarn start' to start the app.
- Installing using NPM
- Run the command 'npm install' at the root of the repository
- After Installation, configure the '.env' file and 'config.js' files according to the Environment Set up guide
- Run the command 'npm start' to start the app.
- Installing Using Yarn
- After the app starts, navigate to '/test' route followed after your apps hosted domain.
- Test for if the file upload, Download is working or not.
- If they are working well and good, else create an issue with the steps to replicate the issue and any error logs for help.
The Request format is:
- method:
POST
- form-encType:
multipart/form-data
- url for Image uploads:
/upld/img
- url for Video uploads:
/upld/vid
- url for Audio uploads:
/upld/aud
- url for Other uploads:
/upld/oth
payload:
{
"uName":"", // User name of the uploader
"fileType":"", // Type of file
"file": // File that you want to upload
}
The Response to that Request is this:
{
"url": "", // URL through which you can access the file
"body": { // Request body
"uName": "",
"fileType": ""
},
"file": { // information on the file that has been uploaded
"fieldname": "",
"originalname": "",
"encoding": "",
"mimetype": "",
"destination": "",
"filename": "",
"path": "",
"size": ""
}
}
- Code Documentation pending