I am trying to write a Jupyter Notebook extension in which I also have to create a submit button which should post the current notebook file to the external server.
The trouble I am facing is how can I get the notebook file object and then post it. I am not sure if there is a way to get the orginal ipynb file and post it.
I can get a browser URL for example "http://localhost:8888/notebooks/Untitled.ipynb", so I figured I could send a get request to this URL and then post it but the get request obviously sends an HTML file of a notebook which is opened in the browser.
Here is my code
var that = Jupyter.menubar;
var browserURL = Jupyter.notebook.container[0].baseURI;
var request = new XMLHttpRequest();
request.open('GET', browserURL, true); // Send get request to browser URL
request.onload = function() {
var reader = new FileReader();
reader.readAsDataURL(request.response);
reader.onload = function(e){
var notebookFile = e.target.result; // returned File
$.ajax({
url : 'http://example.com/hello.php',
type : "POST",
dataType: "json",
crossDomain: true,
data: {
'file': notebookFile,
'msg': "Hello"
},
success: function(data) {
console.log("Success");
},
error: function(xhr, status, error) {
console.log("error");
}
});
};
};
request.send();
My question is that how can I get the notebook file that I am working on, so I can post it to the server.
Thank you