You can use OOTB file upload facility for SharePoint library using below url:
https://sharepoint.contoso.com/sites/YourSiteUrl/_layouts/15/Upload.aspx?List={Destination LIST GUID}&RootFolder="ServerRelativeURL of destination folder"
Note: Upper mentioned url is working in SharePoint 2013. For SharePOint 2010, just open the library in IE browser --> click on "upload document" button, --> popup will be opened -->right click on that and click on properties and you will get proper url. It might be just 14 hive change in the URL.
Create Folder using JSOM:
<div><button onclick=" createFolder ()">Click here to AddaFieldtoList</button></div>
<div id="displayDiv"></div>
<script type="text/javascript">
function createFolder() {
var clientContext;
var oWebsite;
var oList;
var itemCreateInfo;
clientContext = new SP.ClientContext.get_current();
oWebsite = clientContext.get_web();
oList = oWebsite.get_lists().getByTitle("Shared Documents");
itemCreateInfo = new SP.ListItemCreationInformation();
itemCreateInfo.set_underlyingObjectType(SP.FileSystemObjectType.folder);
itemCreateInfo.set_leafName("My new folder!");
this.oListItem = oList.addItem(itemCreateInfo);
this.oListItem.update();
clientContext.load(this.oListItem);
clientContext.executeQueryAsync(
Function.createDelegate(this, successHandler),
Function.createDelegate(this, errorHandler)
);
function successHandler() {
alert("New folder is created successfully!");
}
function errorHandler() { alert("Error: "+arguments[1].get_message());
}
}
</script>
Add file to SharePoint Library using REST api:
function sendFileToServer(filename, file)
{
var reader = new FileReader();
reader.onloadend = function(evt)
{
if (evt.target.readyState == FileReader.DONE)
{
var folder = localStorage.getItem('FolderName');
var serverRelativeUrlToFolder = 'LibraryName/' + folder;
var buffer = evt.target.result;
//Upload to Specific folder
var docLibraryEndpoint = String.format( "{0}/_api/web/getfolderbyserverrelativeurl('{1}')/files" +
"/add(overwrite=true,url='{2}')",
_spPageContextInfo.webAbsoluteUrl, serverRelativeUrlToFolder, filename
);
$.ajax({
url: docLibraryEndpoint,
type: "POST",
data: buffer,
processData: false,
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success:function()
{
alert("Document uploaded successfully");
},
error:function()
{
alert("Failed to upload the document");
}
});
}
};
reader.readAsArrayBuffer(file);
}
References: