Commit 3344f4a3 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fixed and enhanced upload commands.

parent 0e183e2c
......@@ -398,6 +398,8 @@ export class ApiProviderComponent extends React.Component {
api.getInfo().then(info => {
this.setState({info: info})
}).catch(error => {
this.props.raiseError(error)
})
return api
......
......@@ -412,7 +412,7 @@ class Uploads extends React.Component {
\`\`\`
`}</Markdown>
</div>
<CopyToClipboard text={uploadCommand} onCopy={() => null}>
<CopyToClipboard text={uploadCommand.upload_command} onCopy={() => null}>
<Tooltip title="Copy command to clipboard">
<IconButton>
<ClipboardIcon />
......@@ -421,6 +421,9 @@ class Uploads extends React.Component {
{/* <button>Copy to clipboard with button</button> */}
</CopyToClipboard>
<HelpDialog icon={<MoreIcon/>} maxWidth="md" title="Alternative shell commands" content={`
As an experienced shell and *curl* user, you can modify the commands to
your liking.
The given command can be modified. To see progress on large files, use
\`\`\`
${uploadCommand.upload_progress_command}
......@@ -429,8 +432,27 @@ class Uploads extends React.Component {
\`\`\`
${uploadCommand.upload_tar_command}
\`\`\`
As an experienced shell and *curl* user, you can modify the commands to
your liking. NOMAD accepts stream data (\`-H <local_file>\`) or multi-form data (\`-f file=@<local_file>\`).
### Form data vs. streaming
NOMAD accepts stream data (\`-T <local_file>\`) (like in the
examples above) or multi-part form data (\`-X PUT -f file=@<local_file>\`):
\`\`\`
${uploadCommand.upload_command_form}
\`\`\`
We generally recommend to use streaming, because form data can produce very
large HTTP request on large files. Form data has the advantage of carrying
more information (e.g. the file name) to our servers (see below).
#### Upload names
With multi-part form data (\`-X PUT -f file=@<local_file>\`), your upload will
be named after the file by default. With stream data (\`-T <local_file>\`)
there will be no default name. To set a custom name, you can use the URL
parameter \`name\`:
\`\`\`
${uploadCommand.upload_command_with_name}
\`\`\`
Make sure to user proper [URL encoding](https://www.w3schools.com/tags/ref_urlencode.asp)
and shell encoding, if your name contains spaces or other special characters.
`}/>
</div>
......
......@@ -514,7 +514,9 @@ class UploadResource(Resource):
upload_command_model = api.model('UploadCommand', {
'upload_url': fields.Url,
'upload_command': fields.String,
'upload_command_with_name': fields.String,
'upload_progress_command': fields.String,
'upload_command_form': fields.String,
'upload_tar_command': fields.String
})
......@@ -527,6 +529,7 @@ class UploadCommandResource(Resource):
def get(self):
""" Get url and example command for shell based uploads. """
upload_url = '%s/uploads/?curl=True' % config.api_url()
upload_url_with_name = upload_url + '&name=<name>'
# upload_command = 'curl -X PUT -H "X-Token: %s" "%s" -F file=@<local_file>' % (
# g.user.get_auth_token().decode('utf-8'), upload_url)
......@@ -536,6 +539,12 @@ class UploadCommandResource(Resource):
upload_command = 'curl -H X-Token:%s %s -T <local_file>' % (
g.user.get_auth_token().decode('utf-8'), upload_url)
upload_command_form = 'curl -H X-Token:%s %s -X PUT -F file=@<local_file>' % (
g.user.get_auth_token().decode('utf-8'), upload_url)
upload_command_with_name = 'curl -H X-Token:%s "%s" -X PUT -T <local_file>' % (
g.user.get_auth_token().decode('utf-8'), upload_url_with_name)
upload_progress_command = upload_command + ' | xargs echo'
upload_tar_command = 'tar -cf - <local_folder> | curl -# -H X-Token:%s %s -T - | xargs echo' % (
g.user.get_auth_token().decode('utf-8'), upload_url)
......@@ -543,5 +552,7 @@ class UploadCommandResource(Resource):
return dict(
upload_url=upload_url,
upload_command=upload_command,
upload_command_with_name=upload_command_with_name,
upload_progress_command=upload_progress_command,
upload_command_form=upload_command_form,
upload_tar_command=upload_tar_command), 200
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment