Closed ouankou closed 4 years ago
PWD has a handler to get a file from the container. We don't need to implement a new function. https://github.com/freeCompilerCamp/play-with-compiler/blob/a8e345233629088d3a618c531a5436a2dabfb3b3/handlers/bootstrap.go#L82
The definition is located in: https://github.com/freeCompilerCamp/play-with-compiler/blob/master/handlers/file_instance.go
To use this function, assume we open a tutorial and create test.txt
in the home folder /home/freecc
. For any sandbox, a session id and a instance id will be generated automatically. The following GET
request will get /home/freecc/test.txt
curl --request GET lab.freecompilercamp.org:5010/sessions/bsk4ctgq4uig0s44264g/instances/bsk4ctgq_bsk4ctoq4uig0s442650/file?path=%2Fhome%2Ffreecc%2Ftest.txt
The URL pattern is <pwc_url>/sessions/<session_id>/instances/<instance_id>/file?path=<encoded file path>
.
The parameter at the end is to indicate the demanding file. The file path after url encoding is the value of the key path
.
The returned file content is encoded to Base64 format.
To be safe, the file should be passed to
/tmp
and never be executed. Then the file can be downloaded from frontend by user.